simple .htaccess redirect : how to redirect with parameters?

痴心易碎 提交于 2019-12-18 17:05:34

问题


My goal is simply to redirect:

/jsn.php?parameters to http://www.site2.com/jsn.php?parameters

I tried with

Redirect permanent /jsn.php(.)* http://www.site2.com/jsn.php$1

回答1:


Query string parameters are automatically passed, you simply want to do this:

Redirect permanent /jsn.php http://www.site2.com/jsn.php

The (.)* doesn't work with the Redirect directive, you were probably thinking of RedirectMatch, but either way, you don't need it. And also (.)* should be (.*), otherwise the $1 backreference would only get the first character.




回答2:


You can use an explicit URL rewrite in your .htaccess file:

RewriteRule ^/jsn\.php\?(.*) http://www.site2.com/jsn.php?$1 [R]

Note: You need to escape . and ? because they are also regular expression characters.

If you have a problem using mod_rewrite, post the contents of your file.




回答3:


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(jsn\.php)$ http://www.site2.com/$1 [L,NC,R=301]


来源:https://stackoverflow.com/questions/10745977/simple-htaccess-redirect-how-to-redirect-with-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!