unemployment Posted July 27, 2011 Share Posted July 27, 2011 How do you remove the .php from the file extensions in the URL? I've noticed a lot of companies now don't showcase what type of server side language they use. Is this something that would need to be figured out in .htaccess? Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/ Share on other sites More sharing options...
Maq Posted July 27, 2011 Share Posted July 27, 2011 This is usually done in the .htaccess with mod_rewrite, we have a section for that, I'll move you there. Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1247972 Share on other sites More sharing options...
unemployment Posted July 27, 2011 Author Share Posted July 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1247986 Share on other sites More sharing options...
AyKay47 Posted July 27, 2011 Share Posted July 27, 2011 I have not studied .htacces yet, so I won't pretend to know about this...however I found a tutorial on the subject http://www.easymodrewrite.com/example-extensions Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1247993 Share on other sites More sharing options...
cags Posted July 27, 2011 Share Posted July 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1248115 Share on other sites More sharing options...
unemployment Posted July 27, 2011 Author Share Posted July 27, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1248131 Share on other sites More sharing options...
cags Posted July 27, 2011 Share Posted July 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242976-remove-php-file-extensions/#findComment-1248165 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.