Jump to content

Rewrite


hackalive

Recommended Posts

Hi guys,I

 

have this rewrite code:

 

RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^([^/.]+)/?$ /$1.php [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L]

 

But i need something that does a IF cant find with .php then try it wil .html otherwise fail (then the server takes over and shows 404 error).

 

Any suggestions?

 

I have tried:


RewriteRule ^([^/.]+)/?$ /$1.tmp [N]
RewriteRule ^([^/.]+)/?$ /$1.php [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L]

 

Hoping it may work - but with no luck.

 

Cheers in advance.

Link to comment
https://forums.phpfreaks.com/topic/269151-rewrite/
Share on other sites

This works though

 


RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ /$1.html [N]
RewriteRule ^([^/.]+)/?$ /$1.php [L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L]

 

Not sure what this is for RewriteCond %{REQUEST_FILENAME} !-d

 

Need to make it work to a folder now though??

 

so like redirects/%{REQUEST_FILENAME}.html -f

Link to comment
https://forums.phpfreaks.com/topic/269151-rewrite/#findComment-1383180
Share on other sites

...Maybe?

# the next Rule only matches if there's a *.html file for the request
RewriteCond %{REQUEST_FILENAME}.html -f
# the next Rule only matches if the request isn't for a directory
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite the request to include a .html suffix
RewriteRule ^([^/.]+)/?$ /$1.html [N]

# the earlier Conds do not apply to the Rules below

# rewrite the request to include a .php suffix
RewriteRule ^([^/.]+)/?$ /$1.php [L]
# same as above but allow a parent folder
RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L]

Link to comment
https://forums.phpfreaks.com/topic/269151-rewrite/#findComment-1383373
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.