Forum Moderators: phranque

Message Too Old, No Replies

How to rewrite if exists a php file with the same name?

mod_rewrite trouble

         

zeldix

11:02 pm on Jan 28, 2010 (gmt 0)

10+ Year Member



Hello,

I want to rewrite http_//mydomain.com/f to http_//mydomain.com/

This is my .htaccess code:

Rewriterule ^f$ / [R=301,L]

rewrite works, but if exists a file called f.php, then doesn't work (I have 404 error when f.php exists)

I tried to do this:

RewriteCond %{REQUEST_FILENAME} !-f
Rewriterule ^f$ / [R=301,L]

also I tried to do this:

Rewriterule ^f([^\.php])$ / [R=301,L]

But doesn't work. I need help Is possible this rewrite? or I should delete f.php file? Please help me Thanks

jdMorgan

4:52 am on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're on Apache 1.x, disable MultiViews (unless you use them).

If you're on Apache 2.x, disable MultiViews and disable AcceptPathInfo (unless you use them).

Directives:


Options -MultiViews
AcceptPathInfo Off

Also, if this is really supposed to be an external redirect instead of an internal rewrite, I suggest that you specify the full URL to avoid potential canonicalization problems.

RewriteRule ^f$ [i]http://www.example.com[/i]/ [R=301,L]

Jim

zeldix

1:14 pm on Jan 29, 2010 (gmt 0)

10+ Year Member



It works. Thank you! I was a lot of time asking in google for answer this question. Thanks!