hackalive Posted October 6, 2012 Share Posted October 6, 2012 (edited) 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 October 6, 2012 by hackalive Quote Link to comment Share on other sites More sharing options...
requinix Posted October 6, 2012 Share Posted October 6, 2012 Use a RewriteCond to see if the hypothetical file exists. Like RewriteCond %{REQUEST_FILENAME}.php -f Oh, and it's REQUEST_FILENAME, not _URI. Quote Link to comment Share on other sites More sharing options...
hackalive Posted October 6, 2012 Author Share Posted October 6, 2012 I had tried RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/.]+)/?$ /$1.tmp [N] RewriteRule ^([^/.]+)/?$ /$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L] does not work Quote Link to comment Share on other sites More sharing options...
hackalive Posted October 6, 2012 Author Share Posted October 6, 2012 (edited) 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 October 6, 2012 by hackalive Quote Link to comment Share on other sites More sharing options...
requinix Posted October 6, 2012 Share Posted October 6, 2012 ...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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.