Jump to content

Remove .php File Extensions


unemployment

Recommended Posts

This is usually done in the .htaccess with mod_rewrite, we have a section for that, I'll move you there.

 

Thanks Maq.  I'm a bit lost with how to do this as a mod_rewrite.  I also really don't want to have to rename my links since my application is almost fully built. 

Link to comment
Share on other sites

I also really don't want to have to rename my links since my application is almost fully built. 

 

If you want your links to not contain a file extension, you have to remove the file extension. That's all there is too it I'm afraid. All mod_rewrite does is intercepts incoming requests and serves up a specific resource, which you configure based on various patterns. For example, if your site uses php files you could use something like the following (quick example, could be typos)...

 

RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^[^.]+$ /%{REQUEST_URI}.php [L]

 

...this will take all requests to the server for files that don't exist and attempt to serve up a file with that name. So let's say somebody request http://www.domain.com/contact then it would attempt to serve up the file http://www.domain.com/contact.php.

Link to comment
Share on other sites

Does anyone know the impact this has on SEO?  I have successfully redirected links to cleaner looking urls, but now the file can be accessed in two place.

 

for example you can go to mysite.com/contact and mysite.com/contact.php

 

I really don't want both accessible.  Any way to force a page load of contact.php to go to just contact?

 

Link to comment
Share on other sites

It's possible but it starts to get a bit hacky at that point. One way is to 301 redirect all requests to the page that don't have a specific query string, then simply append that query string when you rewrite the URI.

Link to comment
Share on other sites

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.