Enoque Duarte
Enoque Duarte

Reputation: 689

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?

Upvotes: 1

Views: 1342

Answers (1)

anubhava
anubhava

Reputation: 785286

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]

Upvotes: 3

Related Questions