重定向的站点根目录使用的.htaccess子目录子目录、根目录、重定向、站点

2023-09-02 20:40:29 作者:孤身走天涯

我的一个网站拥有所有存储在一个子目录中的文件。 previously,我使​​用301重定向发送从 site.com/specific/page 游客 site.com/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.com/specific/page to site.com/subdirectory/specific/page.

我现在用这样的:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]

这意味着URL是清洁的。然而,有没有一种方法,使htaccess的重定向使用子目录清洁网址的人吗?也就是说,如果有人去 site.com/subdirectory/specific/page ,有没有办法让网址 site.com/specific/page ,同时显示来自内容 site.com/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.com/subdirectory/specific/page, is there a way to make the URL site.com/specific/page, while showing the content from site.com/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.