hackalive Posted October 6, 2012 Share Posted October 6, 2012 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 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. Link to comment https://forums.phpfreaks.com/topic/269151-rewrite/#findComment-1383171 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 Link to comment https://forums.phpfreaks.com/topic/269151-rewrite/#findComment-1383178 Share on other sites More sharing options...
hackalive Posted October 6, 2012 Author Share Posted October 6, 2012 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 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] Link to comment https://forums.phpfreaks.com/topic/269151-rewrite/#findComment-1383373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.