我制作了一个使用以下链接的php Web应用程序:
<a href="/asset/image.ext">Link</a> ... onClick="window.location.href='/asset/image.ext'" ... <? header("Location: /login"); ?> etc.
您可能已经注意到,几乎每个链接都以/
开头。
许多链接都在.htaccess
中重写,如下所示:
Options All -Indexes RewriteEngine on RewriteRule ^login/error_418$ assets/common/login.php?&error [L] RewriteRule ^login$ assets/common/login.php [L] RewriteRule ^settings/change-profile-picture$ index.php?page=settings&command=profilePicture [L] RewriteRule ^settings/change-password/error-requirements$ index.php?page=settings&command=password&error=requirements [L] RewriteRule ^settings/change-password/error-missmatch$ index.php?page=settings&command=password&error=missmatch [L] RewriteRule ^settings/change-password/error-418$ index.php?page=settings&command=password&error=418 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)/grades$ index.php?page=grades&course=$1 [L]
现在我需要在一个网络服务器上移动它,NOT
位于root direcotry
但在文件夹中......
我现在如何将所有根链接重定向到该文件夹?
答案 0 :(得分:0)
首先将现有规则放在/folder/.htaccess
中,如下所示:
Options All -Indexes
RewriteEngine on
RewriteBase /folder/
RewriteRule ^login/error_418$ assets/common/login.php?&error [L]
RewriteRule ^login$ assets/common/login.php [L]
RewriteRule ^settings/change-profile-picture$ index.php?page=settings&command=profilePicture [L]
RewriteRule ^settings/change-password/error-requirements$ index.php?page=settings&command=password&error=requirements [L]
RewriteRule ^settings/change-password/error-missmatch$ index.php?page=settings&command=password&error=missmatch [L]
RewriteRule ^settings/change-password/error-418$ index.php?page=settings&command=password&error=418 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/grades$ index.php?page=grades&course=$1 [L]
然后在root .htaccess中创建一个规则:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!folder/).*)$ folder/$1 [L,NC]