.htaccess - 重定向到本地主机仪表板而不是项目根目录
问题描述
我在 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]
解决方案
如果您使用的是,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]
确保清除浏览器缓存或使用新浏览器进行测试。
推荐阅读
- python - 绘制公司的增长率
- reactjs - 如何使用钩子将数据从一个组件传递到另一个组件
- python - pygame 函数 pygame.rect.fit() 是如何工作的?
- laravel-8 - 在 laravel 8 中急切加载(如何在刀片中使用)
- python - 无法从元素中抓取文本
- xml - 如何添加带有文本的 XML 节点
- laravel - 未检测到包服务提供者的依赖注入
- javascript - WebView2 - 调用/执行 Javascript 函数
- powerbi - 在 DAX 中应用具有日期条件的帕累托原理
- android - 如何在 android studio/kotlin/observer/ 中只观察一侧