Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

.htaccess - Remove php extension from subfolder url

I am trying to add some other page for my project. But i have one question about php extension.

So i am using htaccess for some url like following htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*)index.php($| |?)
RewriteRule ^ /%1 [R=301,L]

RewriteRule ^friends/([w-]+)/?$ /friends.php?username=$1 [L,QSA]
RewriteRule ^followers/([w-]+)/?$ /followers.php?username=$1 [L,QSA]
RewriteRule ^status/([w-]+)/?$ /status.php?msgID=$1 [L,QSA]
RewriteRule ^following/([w-]+)/?$ /following.php?username=$1 [L,QSA]
RewriteRule ^followers/([w-]+)/?$ /followers.php?username=$1 [L,QSA]
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ /profile.php?username=$1 [L,QSA]

Now, i have created photos.php from the details folder and the link is :

<a href="http://www.name.com/details/photos.php">Go Photos</a>

When i click the Go Photos link i want to remove that url php extension like

http://www.name.com/details/photos

I have still tryed some answer from stackOverflow

Remove .php extension from url

Remove php extension from url

but that answers gives me 404 page not found.

How can i remove .php extension from url anyone can help me here ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need additional rules for removing .php extension.

Use these rules:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} s/+(.+?).php[s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteRule ^(.*)index.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^status/([w-]+)/?$ status.php?msgID=$1 [L,QSA]

RewriteRule ^(following|followers|friends)/([w-]+)/?$ $1.php?username=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteRule (?:^|/)([w-]+)/?$ profile.php?username=$1 [L,QSA]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...