首页 > 解决方案 > 重定向到本地主机仪表板而不是项目根目录

问题描述

我在 localhost 中有一个站点 - ourallnews. 我想将所有关键字 - 重定向index, index.php, index.html到站点根目录 - localhost/ourallnews/。我已经应用了以下规则,.htaccess但它被重定向到 - localhost/dashboard/。如何解决?

RewriteEngine on
RewriteBase /ourallnews/
RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L]

RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ category.php?cat=$1 [L,QSA]

标签: .htaccess

解决方案


如果您使用的是,RewriteBase那么只需在重定向时使用相对链接:

RewriteEngine on
RewriteBase /ourallnews/

RewriteRule ^(.*)index\.(?:php|html?)$ $1 [R=301,NC,NE,L]

RewriteCond %{THE_REQUEST} /category(?:\.php)?\?cat=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ category.php?cat=$1 [L,QSA]

确保清除浏览器缓存或使用新浏览器进行测试。


推荐阅读