php - CodeIgniter 中的 301 重定向有 ?问题

标签 php .htaccess codeigniter mod-rewrite redirect

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/

相关文章:

.htaccess 重定向 .php 和 .html 请求

apache - .htaccess - 如何在某些页面上设置 SSL(脚本需要修改)

php - 实时服务器显示 404 错误,但不在本地,codeigniter 3

php - 基于 PHP (CodeIgniter) 的工作板的良好搜索服务?

php - 我可以更改 Yoast 在 WordPress 站点中生成的描述元标记的内容吗?

php 单例每个对象具有不同的标识符

.htaccess - web.config 中的 URL 重写不适用于子目录中的 Slim PHP API

php - 用户使用 codeigniter 登录后无法将配置文件数据更新到数据库中

php - 如何在多个页面加载时存储变量值

javascript - 站点使用 jquery 和 wp_enqueue_script 显示空白屏幕