【问题标题】:.htaccess redirect url with parameters in a new url.htaccess 重定向 url 与新 url 中的参数
【发布时间】:2022-01-31 15:34:53
【问题描述】:

我需要使用 .htaccess 文件在我的新链接中重定向我的旧链接(已删除), 例如,

From: http://www.example.com/page.php?value=2 (deleted)
To: http://www.example.com/detail.php?d=150

我试过这个,但没有用。因为文件(page.php)不存在,所以服务器给我404 page not found。

我的 .htaccess

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine On
RewriteRule http://www.example.com/page.php?value=2 http://www.example.it/detail.php?d=150 [END,R=301]
order deny,allow

你能帮帮我吗?

【问题讨论】:

标签: apache .htaccess mod-rewrite url-rewriting url-redirection


【解决方案1】:

RewriteRule directive 不接收整个 url,但 URI 中相对于你的 htaccess 文件的指令的部分在里面。此外,它不接收查询参数,您必须使用RewriteCond directive 访问它们。所以,应该是:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^value=2$
RewriteRule ^page.php$ /detail.php?d=150 [R=301,L,QSD]

【讨论】:

    【解决方案2】:

    试试:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} /page\.php\?value=2$
    RewriteRule ^ http://example.it?page.php?d=150 [L,R]
    

    这将重定向

    参考: https://httpd.apache.org/docs/current/mod/mod_rewrite.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 2011-12-24
      • 2016-01-09
      相关资源
      最近更新 更多