使用htaccess更改php页面网址

时间:2011-11-15 21:13:47

标签: php .htaccess

我想从

更改网址
http://mywebsite/address.php?state=oh&office_id=1425

http://mywebsite/office/{variable inside my php page}.php

感谢您能帮助我

2 个答案:

答案 0 :(得分:3)

这应该有效:

RewriteEngine On

RewriteRule ^office/([0-9]+).php$ address.php?state=oh&office_id=$1

哪会导致:

http://expample.com/office/1425.php

或者如果您希望状态也是动态的,您可以这样做:

RewriteEngine On

RewriteRule ^office/([a-zA-Z]+)/([0-9]+).php$ address.php?state=$1&office_id=$2

哪会导致:

http://expample.com/office/oh/1425.php

答案 1 :(得分:1)

我建议看一下 mod_rewrite Apache模块。 您可以使用它进行各种URL操作。

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

初学者指南:

http://www.workingwith.me.uk/articles/scripting/mod_rewrite