John84 Posted April 13, 2020 Share Posted April 13, 2020 Hi all I have this htaccess code to 1: Remove php from any URLS 2: Add a slash to the URL RewriteEngine On # redirect PHP or HTM to no extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.(php|html?) [NC] RewriteRule ^ /%1/ [L,R=301] ## Adding a trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301] # check to see if the request is for a PHP file and rewite to no extension: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^/?(.*)$ /$1.php [L] If I go to www.domain.com/file.php then it redrects to www.domain.com/file/ which is good but if I go to www.domain.com/file then it doesnt redrect to www.domain.com/file/ How can I make it so if I go to www.domain.com/file then it adds the slash on the end Lastly. does the code look ok in terms of it conforming to the standards? Thanks, John Quote Link to comment https://forums.phpfreaks.com/topic/310560-htaccess-issue/ Share on other sites More sharing options...
requinix Posted April 13, 2020 Share Posted April 13, 2020 Look carefully at the condition for your first rewrite. Have one redirect that does just the extension and one that does just the slash. (And in that order.) Don't try to do half of both at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/310560-htaccess-issue/#findComment-1576777 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.