lingo5 Posted January 9, 2013 Share Posted January 9, 2013 Hi, I want all my php urls like products.php to show up as /products....so I have created a htaccess file with the following rule: Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L] ...but I does not work and I still get the url with the php extension....any help very much appreciated. thanks Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/ Share on other sites More sharing options...
Beeeeney Posted January 9, 2013 Share Posted January 9, 2013 I found this on Stackoverflow, apparently it works. RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404445 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 thanks beeeeney...but nope...it doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404448 Share on other sites More sharing options...
Beeeeney Posted January 9, 2013 Share Posted January 9, 2013 (edited) But the internet said it would.. Someone else suggested this: Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [L] Edited January 9, 2013 by Beeeeney Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404449 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 nope.... Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404450 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 Be sure that your htaccess file is hidden. Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404453 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 hi jazzman..how do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404455 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 It must start with period. Example: .htaccess Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404456 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 ah ok..yes it starts with period..but I can't get the above rules to work.... Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404458 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 I don't very familiar with .htaccess, so let me check Beeeeney's solution into my local server. Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404462 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 Beeeeney's solutions are correct! Where did you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404468 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 Thanks everyone and sorry..my mistake...had a typo somewhere !!!! THANKS ALL Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404477 Share on other sites More sharing options...
jazzman1 Posted January 9, 2013 Share Posted January 9, 2013 (edited) @lingo5, if you have a simple link on your web page, you could use .htaccess for that purpose . Examples: <a href="products">Products</a> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php If you want to hide a php extension in the url string, I'm not sure that can't be done purely via .htaccess, you should use php to do this, or better JS. Edited January 9, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404488 Share on other sites More sharing options...
lingo5 Posted January 9, 2013 Author Share Posted January 9, 2013 thanks jazzman...I'm doing some research on how to hide php extension in url string....so far I got the first part working !!!! Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404490 Share on other sites More sharing options...
Ninjakreborn Posted January 10, 2013 Share Posted January 10, 2013 Hiding extensions can be found here: http://programanddesign.com/web/htaccess/use-htaccess-to-hide-file-extensions/ Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1404704 Share on other sites More sharing options...
devWhiz Posted January 14, 2013 Share Posted January 14, 2013 For future reference, as an alternative to editing .htaccess you could have made a folder in the root of your website called "products" and then took products.php and renamed it index.php and put it in the products folder, then include any scripts needed to generate the products page. That would show up as www.yoursite.com/products By editing .htaccess, it can work for all scripts with the .php extension, which would be better in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1405500 Share on other sites More sharing options...
lingo5 Posted January 14, 2013 Author Share Posted January 14, 2013 thanks cluel3ss, I'm still working on the .htaccess part Quote Link to comment https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/#findComment-1405615 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.