Options +FollowSymlinks
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|uploads|tt|application/modules/.*/assets|resources|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Redirect 301 /testurl /home/
这是我的 .htaccess
文件,用于检查我的 CodeIgniter 项目中的 301
重定向。
301
重定向工作正常,但问题出在 URL 上。当我尝试...
http://parcmobilenew.eworkdemo.com/testurl
...它重定向到主页,如 .htaccess
中所述,但它在查询字符串中采用请求的 URL,如下所示...
http://parcmobilenew.eworkdemo.com/home?/testurl
如何让 .htaccess
在重定向时不这样做?
最佳答案
- 不要将
Redirect
规则与mod_alias
规则混合使用。 - 在内部重写之前保留重定向规则。
您可以使用此代码:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^testurl/?$ /home/? [L,NC,R=301]
RewriteCond $1 !^(index\.php|assets|uploads|tt|application/modules/.*/assets|resources|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
最好在新浏览器中测试以避免旧的 301 缓存。
关于php - CodeIgniter 中的 301 重定向有 ?问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27438646/