Pain Posted June 30, 2012 Share Posted June 30, 2012 Hello again. I've been trying to hide my url extension lately. If it is yourdomain.com/management.php then i wan to make it yourdomain.com/management After exploring various tutorials i've found out that writing the following code in the .htaccess file would help. RewriteEngine On RewriteCond %{REQUEST_URI} !-d RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !\.php$ RewriteRule ^(.*)$ /$1.php [L] Also i've changed all internal links in my website (eg. from <a href="management.php">Link</a> to <a href="/management">Link</a> ) However it still does not work :s Is there something wrong with the code? Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/ Share on other sites More sharing options...
ignace Posted July 1, 2012 Share Posted July 1, 2012 http://newmediarts.blogspot.be/2007/01/hide-file-extensions-in-urls-with.html RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358328 Share on other sites More sharing options...
requinix Posted July 1, 2012 Share Posted July 1, 2012 There's also Options +MultiViews which allows you to omit extensions for any known (by Apache) file type. Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358335 Share on other sites More sharing options...
Pain Posted July 1, 2012 Author Share Posted July 1, 2012 Still not working for some reason Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358427 Share on other sites More sharing options...
Pain Posted July 1, 2012 Author Share Posted July 1, 2012 http://newmediarts.blogspot.be/2007/01/hide-file-extensions-in-urls-with.html RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php I saw some other examples of mod rewriting and i figured that i have o do something with the last line RewriteRule ^(.*)$ $1.php So if i want make it from myFile3.php to myFile then i should write something in that 4th line? Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358429 Share on other sites More sharing options...
Pain Posted July 2, 2012 Author Share Posted July 2, 2012 That you for your help guys. I found a solution. I've added one line at the top: RewriteBase / So full code would be; RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358443 Share on other sites More sharing options...
Pain Posted July 2, 2012 Author Share Posted July 2, 2012 I will not create yet another topic and ask this in here. I've got this url: http://kingstonuni.atspace.co.uk/social/user_profile.php?id=14 which i want to convert to: http://kingstonuni.atspace.co.uk/social/14 or: http://kingstonuni.atspace.co.uk/social/user_profile/14 what extra line of code should i add? Thank you very much for your kind help. Quote Link to comment https://forums.phpfreaks.com/topic/265053-hiding-php-or-any-other-extension-with-htaccess/#findComment-1358606 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.