2

我有一个从子目录运行的站点 - 托管在 HostGator 上。大多数 htaccess 规则都可以重定向到子目录,除了一个。

如果我去 example.com/products - 我得到一个不可见的重定向到 example.com/subfolder/products - 它在地址栏中正确显示为 example.com/products

但是,如果我转到 example.com/news - 我得到一个可见的重定向到 example.com/subfolder/news - 它在地址栏中错误地显示为 example.com/subfolder/news

以下是我在根文件夹中使用的 .htaccess 代码:

RewriteEngine on
RewriteRule ^$ /subfolder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]

供参考:如果我在浏览器中输入 example.com/news,我会明显地重定向到 example.com/subfolder/news - 但是,如果我第二次在浏览器中输入 example.com/news,我会被隐形重定向!

Google 已抓取该网站并提供可见的重定向网址(因此它们在 Google 中显示为 example.com/subfolder/news)

更新:

在该.htaccess文件中,我拥有它的唯一另一行Options -Indexes

在子文件 .htaccess文件中我也有

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

ErrorDocument 403 http://www.example.com/403
ErrorDocument 404 http://www.example.com/404
ErrorDocument 500 http://www.example.com/500

如果这有任何影响,我和 HostGator 在一起?

4

0 回答 0