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
Share on other sites

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 by Beeeeney
Link to comment
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.

Edited by jazzman1
Link to comment
Share on other sites

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.

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.