开发者

htaccess mod rewrite changes http://www to http:/www

开发者 https://www.devze.com 2022-12-30 22:01 出处:网络
I want to replace calls like this: www.mysite.com/sub/file.php?param1=x&param2=http://www.someurl.com

I want to replace calls like this:

www.mysite.com/sub/file.php?param1=x&param2=http://www.someurl.com

with:

www.mysite.com/sub/param1/param2

Param 1 is an integer number Param 2 is a url

I wrote this rewrite rule in htaccess:

RewriteCond %{REQUEST_URI} \/sub\/
RewriteRule sub\/([0-9]+)\/(.*)$  sub\/file.php?param1=$2&param2=$1 [L] 

Unfortunately开发者_开发问答 param2 (the URL) starts with http:/www.someurl.com instead of http://www.someurl.com (note the single slash).

Any idea what causes it? When I call the same file with same parameters in the format www.mysite.com/sub/file.php?param1=x&param2=http://www.someurl.com , param2 does appear OK so it must be something with the rewrite rule.


You need to grab the value from THE_REQUEST:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /sub/[0-9]+/([^?\ ]+)
RewriteRule ^sub/([0-9]+)/  sub/file.php?param1=$1&param2=%1 [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号