Avatar of Kinderly Wade
Kinderly Wade
Flag 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.
Web ComponentsWeb DevelopmentWeb Applications

Avatar of undefined
Last Comment
Edwin Hoffer

8/22/2022 - Mon
Gary

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]
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
Gary

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gary

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

???
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Kinderly Wade

ASKER
Hi Gary,

You are absolutely correct! I need to redirect the page and each page will not show .php extension.
Edwin Hoffer

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
Kinderly Wade

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Edwin Hoffer

Sure :)