Jump to content

please help with url rewrite


lingo5

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/272898-please-help-with-url-rewrite/
Share on other sites

@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.

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.

Archived

This topic is now archived and is closed to further replies.

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