首页 > 解决方案 > 在子文件夹中重写 Htaccess 中的 Base

问题描述

我网站上的所有路径都是相对 URL,并以 / 开头,这在生产中很好,但我将它带回开发并将其放在 /app 的路径下我尝试使用 RewriteBase 设置但它没有改变任何网站上的路径。我错过了什么吗?

RewriteEngine On
RewriteBase /app/
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/(.+)/(.+)$ $1.php?type=$2&loan-type=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/(.+)$ $1.php?type=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [L,QSA]

将所有根目录重定向到 /apps 的根 htaccess 设置,而不仅仅是 /apps 的子目录。

RewriteEngine On

RewriteRule ^(?!app/)(.+)$ /app/$1 [L,NC]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

标签: apache.htaccess

解决方案


您可以在站点根目录 .htaccess 中使用此规则:

RewriteEngine On

RewriteRule ^(?!app/)(.+)$ app/$1 [L,NC]

推荐阅读