.htaccess rewrite url and removing .php

2019-08-10 20:05发布

问题:

I want to remove the .php from the url through htaccess file. for example home.php to home I'm using the following rewrite rule in htaccess file.

  RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

and also I want to rewrite the url. for example

/detail.php?ca=38&title=rewrite uri sample 

to

detail/article/38/rewrite uri sample

回答1:

I try search to the entire www, then I have an answer..

RewriteEngine On
Options +FollowSymLinks -MultiViews

RewriteRule    ^article/([0-9]+)/?$    detail.php?ca=$1    [NC,L]   
RewriteRule    ^article/([0-9]+)/([A-Za-z0-9-]+)/?$    detail.php?ca=$1&title=$2    [NC,L]  

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


回答2:

Use

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

For GoDaddy

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