首页 文章

htaccess中的301重定向不会确认查询字符串

提问于
浏览
1

我需要将旧的动态页面重定向到新的关键字 - 网址:

Redirect 301 http://www.domain.com/index.php?id=100 http://www.domain.com/newhello

但是,我一直收到404错误:

在此服务器上找不到请求的URL /index.php .

就好像apache忽略了查询字符串,只看了URL的'index.php'部分 .

我也玩过'RewriteRule'和'RedirectMatch 301',但效果相同 . 任何意见,将不胜感激 .

编辑 - 下面是整个.htaccess文件内容的粘贴 . 请注意,这是在根目录中:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !newroot/
RewriteRule (.*) /newroot/$1 [L]

#successful 301 redirect or mod_rewrite directives will be listed from here.

1 回答

  • 2

    您无法使用 Redirect 指令匹配QUERY_STRING . 在你的根.htaccess文件中使用 mod_rewrite 代替这样:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^id=100$
    RewriteRule ^index\.php$ http://www.domain.com/newhello? [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$
    RewriteCond %{REQUEST_URI} !/newroot/
    RewriteRule (.*) /newroot/$1 [L]
    

相关问题