简体   繁体   中英

Apache .htaccess rewrite rule removing double slash unintentionally

I have a simple rewrite rule which passes a simple string (attr ' mode ') and a url (attr target_url ) with format: http://dummypage.com/

RewriteRule ^test/([^/.]*)/(.*)$ /index.php?mode=$1&target_url=$2

converting

mydomain.com/test/stringparam/http://dummypage.com/

to

mydomain.com/index.php?mode=stringparam&target_url=http:/dummypage.com/

notice that it changed http://dummypage.com/ to http:/dummypage.com/, why does it remove double slashes?

You cannot match this kind of URI using RewriteRule . Use THE_REQUEST variable to match it. THE_REQUEST variable represents original request received by Apache from your browser.

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+test/([^/]+)/([^\s]*)\s [NC]
RewriteRule ^ /index.php?mode=%1&target_url=%2 [L,QSA,NE]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM