Link to home
Start Free TrialLog in
Avatar of Kinderly Wade
Kinderly WadeFlag for United States of America

asked on

modify .htaccess

Dear experts,

I wish to know some concept about htaccess file.

I've tried this code but doesn't work for removing the .php extension:

Options +FollowSymlinks
RewriteEngine on

Redirect /index.html /App/views/login.php

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

I was able to redirect but unable to strip the .php extension

Thanks.
Avatar of Gary
Gary
Flag of Ireland image

Bit confused...
You are trying to link to php files without using the .php extension?


Change
   Redirect /index.html /App/views/login.php
to
   Redirect /index.html /App/views/login

Your rewrite should only be doing the rewrite if the filename minus .php doesn't exist.

   RewriteCond %{REQUEST_FILENAME} -f
   RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
Avatar of Kinderly Wade

ASKER

Hi Gary,

I am new to the Rewrite syntax. I am not sure if I am doing it correctly. THanks

If there is a reference page on rewriteCond or rewriteRule that will be great.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you are wanting to remove the .php extension from any incoming links and do a 301

Then all (extensionless) links should point to the php page

???
Hi Gary,

You are absolutely correct! I need to redirect the page and each page will not show .php extension.
Hello Kinderly,

To hide .php extension use the below code in .haccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Open in new window


and for redirection Redirect /index.html /App/views/login.php to Redirect /index.html /App/views/login, use the below code:

Redirect /index.html /App/views/login

Open in new window


Thanks
Edwin
Hi Edwin,

THanks for the reply. I will use the code for now and I will also definitely look up the regular expression to see if I can adjust with other redirect rules as well. Thanks again
Sure :)