简体   繁体   中英

using htaccess to modify URL

I am working on a php project. I want to remove the ".php" from the URL. 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.

Enable the mod_rewrite in wamp And add following lines in .htaccess of your document root

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.

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

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

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

Options +MultiViews

Add the following in your .htaccess

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

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