Forum Moderators: phranque

Message Too Old, No Replies

Ignoring .php calls

         

asantos

3:46 pm on Sep 24, 2006 (gmt 0)

10+ Year Member



Hi
I implemented this to my site:

RewriteRule ^about/?$ /about.php [NC,L]
RewriteRule ^search/?$ /search.php [NC,L]

So if the user types
www.mysite.com/about he receives about.php data. Till there no problem at all.

But, if the user types (directly)
www.mysite.com/about.php i need the htaccess to send a 404 Not Found msg. How can i do that?

jdMorgan

5:14 pm on Sep 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use RewriteCond to examine %{THE_REQUEST}, which is the original client request, and is not affected by subsequent internal redirects. It it contains about.php, then rewrite to a nonexistent URL in order to generate a 404, use the [F] flag to generate a 403, or simply 301 redirect it to /about.

Jim

[edited by: jdMorgan at 5:14 pm (utc) on Sep. 24, 2006]

asantos

11:53 pm on Sep 24, 2006 (gmt 0)

10+ Year Member



jdMorgan,
yes, but i need a general rule so any *.php requests are redirected as non existent. What should i do?

jdMorgan

1:57 am on Sep 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A request for any .php file, in any subdirectory, will be rewritten to a non-existent filepath, and therefore will return a 404-Not Found (indicating a missing file or a server malfunction):

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*[^/.]+\.php
RewriteRule \.php /path_to_file_that_does_not_exist.hph [L]

A request for any .php file, in any subdirectory, will return a 410-Gone (indicates that the requested resource was intentionally removed):


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*[^/.]+\.php
RewriteRule \.php - [G]

A request for any .php file, in any subdirectory, will return a 301-Moved Permanently redirect to the "proper" path with ".php" removed:


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*[^/.]+\.php
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

Jim