2

I would like to remove the '%252F' from my dynamically created URLs. I have a php-file that creates links with a %2F instead of /. The links are then represented in the URL-Bar as %252F instead of / which leads to some problems.
What I'm trying to achieve with a .htaccess-file is to redirect all %2F to / or rename all %252F to / since I can't change the php-code creating the links.

This is my .htaccess

RewriteEngine on
Options +SymlinksIfOwnerMatch
RewriteBase /

RewriteCond %{HTTP_HOST} subdomain.mydomain.com
RewriteCond %{REQUEST_URI} (.*)/style.css [OR]
RewriteCond %{REQUEST_URI} (.*)/script.js [OR]
RewriteCond %{REQUEST_URI} (.*)/logo.png
RewriteRule (.*) http://www.mydomain.com%{REQUEST_URI} [R=301,NC,L]

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://subdomain.mydomain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\  [NC]
RewriteRule !^/ /%1/%2 [QSA]

RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=([^\s]+) [NC]
RewriteRule ^ %1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?dir=/$1 [L]

I can't get it to work, maybe someone else can help me with this. Thank you very much!

basbebe
  • 567
  • 1
  • 9
  • 25

2 Answers2

0

The lines:

RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\  [NC]
RewriteRule !^/ /%1/%2 [QSA]

RewriteRule ^(/.+)%2f(.*)$ $1/$2 [NC,QSA]

Need to have the leading slash removed. URI's sent through rules in htaccess files have the leading slash stripped off:

RewriteCond %{THE_REQUEST} \ /([^\ \?]*)([^\ \?]*)%2f(\?.*)?\  [NC]
RewriteRule ^ /%1/%2 [QSA]

RewriteRule ^(.+)%2f(.*)$ $1/$2 [NC,QSA,L]

Not sure what the RewriteRule !^/ /%1/%2 [QSA] line is supposed to do, it looks like you're stripping out a trailing slash?

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I found the rule you are reffering to here: [link](http://forum.modrewrite.com/viewtopic.php?f=10&t=6827) But neither of the rules seems to change anything. The following rule gets me rid of the first %252F: `RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=%2F([^\s]+) [NC] RewriteRule ^ %1? [R=301,L]` – basbebe Oct 23 '12 at 07:28
0

I managed to get rid of the first %252F in the URL and the problem of "stacking" slashes:

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://subdomain.mydomain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=%2F([^\s]+) [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?dir=([^\s]+) [NC]
RewriteRule ^ %1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?dir=/$1 [L]

I still have the problem of having %252F in my URLs though.

basbebe
  • 567
  • 1
  • 9
  • 25