1

I have some external links to my site that referrer to pages with a file extension and a trailing slash after that e.g.

http://example.com/folder/page.php/

I can not change these links, but I would like to 301 redirect those links to this format instead:

http://example.com/folder/page/

I've tried this, but it doesn't work:

RewriteRule ^(.*)\.php\/$ /$1/ [R=301,L] 

Any help is appreciated.

1 Answer 1

1

Try this in your /.htaccess file

RewriteEngine On RewriteCond %{THE_REQUEST} /([^.]+)\.php/? [NC] RewriteRule ^ /%1/ [NC,R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ /$1.php [L,NC] 
Sign up to request clarification or add additional context in comments.

7 Comments

Its works! Thanks alot for your help. Care to explain why i works? Are there two separate rewrites in this solution, and is this a 301 redirect?
Keat, rule in your question doesn't work because ,it redirects "foo.php" to /foo, "/foo" doesn't exist on the server, so it returns a 404 error. My rules redirect "/foo.php" to "/foo" and then it mapps "/foo" back to "/foo.php".
Keat, it's 302 Temp redirect, To make it permanent ,change R to R=301 ,eg : [NC,R=301,L]
Perfect, works lika a charm. And thanks for the explanation. Do i need to change the last line to a R=301 as well?
No, don't change the last line. its not for external redirection. it's for mapping "file" to "file.php" , (internal Redirect)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.