.htaccess - Trail slash is causing 404 error and improper url behavior: APACHE/ PHP -
hoping 1 of can help. developing using php, without framework, therefore of routing rules in .htaccess opposed .php
so here problem. website http://example.com , navigation pretty straight forward, meaning if click 'press' page link go http://example.com/press or http://example.com/press/ both fine.
however, if happen go http://example.com/press/ click internal link in nav, such 'about' etc.. not take '/example' rather '/press/example' shows 404 since there not page or directory handle this.
i tried 'directoryslash off' in .htaccess did prevent of these pages showing if url has / @ end.
i have basic .htaccess setup, see below:
<ifmodule mod_rewrite.c> rewriteengine on # options -indexes # gen config # handle errors errordocument 403 /views/errors/404.php errordocument 404 /views/errors/404.php errordocument 303 /views/errors/404.php # url renamin rewriterule ^(about-us|about-us|about-us)/?$ views/about-us.php [l] rewriterule ^(press|press|press)/?$ views/press.php [l] rewriterule ^(faq|faq|faq)/?$ views/faq.php [l] </ifmodule>
go
http://example.com/press/
click internal link in nav, suchabout
etc.. not take/about
rather/press/about
this problem not due rewrite rules due use of relative paths.
to fix, can add below <head>
section of page's html:
<base href="/" />
so every relative url resolved base url , not current page's url.
Comments
Post a Comment