简体   繁体   中英

.htaccess rewrite url and removing .php

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

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]

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM