简体   繁体   English

使用htaccess修改URL

[英]using htaccess to modify URL

I am working on a php project. 我正在研究一个php项目。 I want to remove the ".php" from the URL. 我想从网址中删除“ .php” Also for - 也适用于-

www.mysite.com/gallery.php?gid=2008

I want like - 我想要-

www.mysite.com/gallery/2008

How can I do this? 我怎样才能做到这一点? I want to check it in local wamp server also. 我也想在本地Wamp服务器中检查它。

Enable the mod_rewrite in wamp And add following lines in .htaccess of your document root 在wamp中启用mod_rewrite ,并在文档根目录的.htaccess中添加以下行

RewriteEngine On
RewriteRule gallery/([0-9]+)/?$ gallery.php?gid=$1 [L]

If you want to remove all other PHP but retaining query string, if you have specifc way to handle query string you have write rules accordingly. 如果要删除所有其他PHP,但保留查询字符串,则如果您有特定的方式来处理查询字符串,则应具有相应的写入规则。

RewriteRule (.*)/? $1.php [QSA,L] 

看看本指南..这应该可以帮助您入门: http : //corz.org/serv/tricks/htaccess2.php

这是允许不含.php的URL 的简单方法

Options +MultiViews

Add the following in your .htaccess 在.htaccess中添加以下内容

RewriteEngine On
RewriteRule ^(.*)\.php\?(.*)=(\d+)$ /$1/$2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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