简体   繁体   English

使用htaccess更改php页面网址

[英]change php page url using htaccess

I want to change the url from 我想改变网址

http://mywebsite/address.php?state=oh&office_id=1425

to

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

appreciate if you can help me 感谢您能帮助我

This should work: 这应该工作:

RewriteEngine On

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

Which would result in: 这将导致:

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

Or if you'd like the state to be dynamic as well, you could do this: 或者,如果您希望状态也是动态的,您可以这样做:

RewriteEngine On

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

Which would result in: 这将导致:

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

I would suggest to have a look at mod_rewrite Apache module. 我建议看一下mod_rewrite Apache模块。 You can do various URL manipulations with it. 您可以使用它进行各种URL操作。

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

Beginner's guide: 初学者指南:

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

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

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