0

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 ?

2

1 Answer 1

3

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]
Sign up to request clarification or add additional context in comments.

13 Comments

Dear i have used also some other think like : <link rel="canonical" href="https://www.name.com/explore/explore"> the explore is explore.php if i use your codes then i can not open explore page it says Internal Server Error. How can i fix this problem ?
oww also following,followers and friends links given 500 Internal Server Error
@anumbhava it is localhost:8888 from my imac . I don't know how can i check error.log
page looks like this : IMAGE
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.