我的一个网站拥有所有存储在一个子目录中的文件。 previously,我使用301重定向发送从 site/specific/page 游客 site/subdirectory/specific/page 。
A site of mine has all the files stored in a subdirectory. Previously, I used a 301 redirect to send visitors from site/specific/page to site/subdirectory/specific/page.
我现在用这样的:
RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?site$ RewriteCond %{REQUEST_URI} !^/subdirectory/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /subdirectory/$1 RewriteCond %{HTTP_HOST} ^(www.)?site$ RewriteRule ^(/)?$ subdirectory/index.php [L]这意味着URL是清洁的。然而,有没有一种方法,使htaccess的重定向使用子目录清洁网址的人吗?也就是说,如果有人去 site/subdirectory/specific/page ,有没有办法让网址 site/specific/page ,同时显示来自内容 site/subdirectory /特定/页?
This means the URL is cleaner. However, is there a way to make the htaccess redirect people using the subdirectory to the cleaner URL? i.e. if someone goes to site/subdirectory/specific/page, is there a way to make the URL site/specific/page, while showing the content from site/subdirectory/specific/page?
推荐答案是的,BUIT而不是改写,妍会重定向。
Yes, buit instead of rewriting, youn would redirect..
RedirectMatch 301 "^/subdirectory/(.*)" "/$1"
这样一来,如果他们直接命中任何子目录中,他们将被重定向到更清洁的网址,你的规则的设置将在踢。
That way, if they hit any subdirectory directly, they will be redirected to the cleaner URL, where your rules above will kick in.
更多推荐
重定向的站点根目录使用的.htaccess子目录
发布评论