【发布时间】:2016-12-29 06:42:56
【问题描述】:
我网站中的动态页面配置了以下 htaccess 规则:
# Dynamic Pages
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
所以页面被重定向到
http://example.com/?url=testpage
到
http://example.com/testpage/
但我也想将 /index.php 重定向到 / (root)。所以当有人进入时
http://example.com/index.php
在浏览器地址栏中应该转到
http://example.com/
为此,我尝试了以下规则:
#index.php to /
RewriteRule ^index\.php$ / [R=301]
虽然这工作正常,但它影响了我之前的 htaccess 规则。以及以下网址
http://example.com/testpage/
自动变成
http://example.com/?url=testpage
当我删除此规则时,之前的动态页面规则可以正常工作。如何让这两个规则在我的 htaccess 文件中正常工作而不会相互冲突?
我完整的 .htaccess 文件是:
Options +FollowSymlinks -MultiViews
#Enable mod rewrite
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
# Dynamic Pages
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
# index.php to /
RewriteRule ^index\.php$ / [R=301]
【问题讨论】:
标签: regex apache .htaccess redirect mod-rewrite