.htaccess rewrite url and removing .php

馋奶兔 提交于 2019-12-11 11:45:56

问题


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]


来源:https://stackoverflow.com/questions/32952264/htaccess-rewrite-url-and-removing-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!