Jump to content

Recommended Posts

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 on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{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.

Link to comment
https://forums.phpfreaks.com/topic/280411-another-mod_rewrite-question/
Share on other sites

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.

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.
  • Solution

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 ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.