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.

Edited by hackalive
Link to comment
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

Edited by hackalive
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.