本文介绍了htaccess 重定向到带有斜杠的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我成功地将所有请求重定向到我的网络服务器的一个子文件夹.
I successfully managed to redirect all requests to a subfolder of my web server.
这是我正在使用的代码:
This is the code I'm using:
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/public/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /public/$1 [L]/public/.htaccess
# redirect all urls that doesn’t have a # trailing slash to urls with a trailing slash # (this is my try) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ $1 [NC]它工作得很好,所以以下重定向工作:
It works perfectly, so the following redirects work:
example -> example/public/ example/foo/ -> example/public/foo/ example/foo/about.html -> example/public/foo/about.html顺便说一下,下面的重定向有问题:
By the way, the following redirect has a problem:
example/foo -> example/public/foo虽然重定向正确,但地址栏中的实际 URL 为:
Although it redirects correctly, the actual URL in the address bar is:
example/public/foo/所以我的问题是:
希望这是有道理的.
推荐答案将此代码放在根目录 .htaccess 中:
Place this code in root .htaccess:
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ $1 [R=301,L] RewriteCond %{REQUEST_URI} !^/public/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /public/$1/ [L]然后删除 /public/.htaccess 因为不需要.
Then just remove /public/.htaccess since that is not needed.
更多推荐
htaccess 重定向到带有斜杠的子文件夹
发布评论