开发者

rewrite php file in htaccess with our without query string

开发者 https://www.devze.com 2023-01-21 09:35 出处:网络
So I have photographs.php, and there are also sections where it will be rewritten as photographs.php?cat=somecategory

So I have photographs.php, and there are also sections where it will be rewritten as photographs.php?cat=somecategory

Question is, in .htaccess how do I get these both to work as such

/photographs and /photographs/someca开发者_运维知识库tegory

so that the $_GET['cat'] variable will be = somecategory


/photographs/(.+) will need to redirect to photographs.php?cat=$1, while /photographs/? will just redirect to photographs.php. if you want to be clever, you can combine it and do it in one line and /photograph will just go to photographs.php?cat=[blank].


First of all you must have the mod_rewrite module activated.

Here's what you need to add to your .htaccess file:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^photographs$ photographs.php [NC]
RewriteRule ^photographs/(.*)$ photographs.php?cat=$1 [NC]

Just some simple replace rules. You can find lots of info on the web about them.

0

精彩评论

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