I have the following rewrite rule in my .htaccess file
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php
This works fine, mapping contact-us to contact-us.php etc. The only thing is, it allows a trailing slash eg contact-us/ which maps to contact-us.php/ Although this still works, it screws up relative addressing to CSS and image files. So is there a way to write the rule so it ignores any trailing / ? Thanks
Perhaps I’ve not phrased it well. The website uses urls without the .php and what the .htaccess file is doing is redirecting to the real url which obviously needs the .php on the end…
The URLs are for files and not directories, therefore, the trailing slash is in error as it specifies a directory name (preceding the /). Delete the optional trailing slash to resolve your problem.
Yeah, my question is why, out of curiousity, were you wanting to add .php extensions back into your URL? Most people make efforts to remove them, not return them after removed
In fact, there’s probably something in your .htaccess removing them already, more likely than not.
@gandalf458, you’re very welcome! I do get rather pedantic over small details and this is one of my bugaboos (pet peeves) so I’m glad that it helped you out of the situation you found yourself in.