开发者

using htaccess to modify URL

开发者 https://www.devze.com 2023-02-16 17:27 出处:网络
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 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? 开发者_JAVA技巧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] 


Have a look at this guide.. this should help you get started: http://corz.org/serv/tricks/htaccess2.php


Here is an easy way to allow the URL without .php:

Options +MultiViews


really multiple question

please search

  • PHP url rewriting using htaccess
  • How to redirect in url by using .htaccess in php?
  • etc


Add the following in your .htaccess

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

精彩评论

暂无评论...
验证码 换一张
取 消