Riparian Posted July 23, 2013 Share Posted July 23, 2013 Hello Scenario I wish to hide the php extension and there is plenty of code on the net to handle this. I think this one would do the job and it work fine except for the instance below. Options +FollowSymLinks -MultiViews# Turn mod_rewrite onRewriteEngine OnRewriteBase /## hide .php extension# To externally redirect /dir/foo.php to /dir/fooRewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]RewriteRule ^ %1 [R,L,NC]## To internally redirect /dir/foo to /dir/foo.phpRewriteCond %{REQUEST_FILENAME}.php -fRewriteRule ^ %{REQUEST_URI}.php [L] The problem When I submit the form and re-load a page I use a named anchor to jump to the required point on the page. With the above code in place nothing happens at all , no form submission, no jumping to the correct page position... nothing except the page reloads. This is the form action example <form name="formName" method="post" action="<?=htmlentities($_SERVER['PHP_SELF'])?>#AnchorName" style="display: inline; margin: 0;"> I have very little knowledge in this area .... Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/ Share on other sites More sharing options...
kicken Posted July 23, 2013 Share Posted July 23, 2013 If you want to hide the .php extension, you should make sure that all the links and form actions your code generates exclude the extension also. That way they do not end up going through the rewrite process and intentionally causing an error. If you're form action there contains .php on the end, the use of the external re-direct to hide the extension will cause the form data and hash tag to be dropped during the redirect. The ability to redirect a version of the url containing .php to the proper no-.php URL should only be there as a way to keep old bookmarks/search engine links working properly. It is not something you should be relying upon to "fix" all your application's links. You application should be generated all correct links that do not include the .php extension. Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/#findComment-1441742 Share on other sites More sharing options...
Riparian Posted July 23, 2013 Author Share Posted July 23, 2013 Thank you Kicken for the reply Am I correct in saying that effectively the $_SERVER[php_SELF] is obsolete if I am to hide the php extension ? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/#findComment-1441743 Share on other sites More sharing options...
Riparian Posted July 23, 2013 Author Share Posted July 23, 2013 Does anyone know if a call to another program e.g. require_once('session.php'); should be changed to require_once('session');as well or just the form actions and and hrefs ? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/#findComment-1441758 Share on other sites More sharing options...
requinix Posted July 23, 2013 Share Posted July 23, 2013 Does anyone know if a call to another program e.g. require_once('session.php'); should be changed to require_once('session');as well or just the form actions and and hrefs ?Hiding the extension is only for the links and the forms and the other things that happen inside the client's browser. You haven't actually renamed the files. Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/#findComment-1441760 Share on other sites More sharing options...
Solution Riparian Posted July 23, 2013 Author Solution Share Posted July 23, 2013 Thank you ... the advice is appreciated. There is just one more problem I have to sort out... the renaming kills my popup info windows... I have tried multiple scripts but they all open a new _blank window rather than a popup. Any ideas ? Quote Link to comment https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/#findComment-1441761 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.