Php 使用htaccess重写url
首先,我是初学者,请详细回答 我的问题是:我想为写一个.htaccess规则Php 使用htaccess重写url,php,.htaccess,url,url-rewriting,Php,.htaccess,Url,Url Rewriting,首先,我是初学者,请详细回答 我的问题是:我想为写一个.htaccess规则 www.asdf.com/city.php?city=New-York to www.asdf.com/New-York 但同时,我还有其他页面,如 www.asdf.com/country.php?country=USA 我想以这样的形象出现 www.asdf.com/USA and www.asdf.com/state.php?country=LA www.asdf.com/LA 我想以这样的形象出现
www.asdf.com/city.php?city=New-York to www.asdf.com/New-York
但同时,我还有其他页面,如
www.asdf.com/country.php?country=USA
我想以这样的形象出现
www.asdf.com/USA and
www.asdf.com/state.php?country=LA
www.asdf.com/LA
我想以这样的形象出现
www.asdf.com/USA and
www.asdf.com/state.php?country=LA
www.asdf.com/LA
我真的很困惑该怎么做,需要帮忙吗,我真的需要解决这个问题
提前感谢我不确定我的方法是否是最好的方法,但我现在就是这样做的:
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?var1=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?var1=$1
将所有页面重写为index.php
在index.php上,我得到的URL是:$URL=$\u SERVER[“REQUEST\u URI”];
然后我进行MYSQL搜索以确定它是什么类型的页面
switch($pagetype){
case "city": include('city.php');
break;
case "country": include('country.php');
break;
}
你有没有看过修改教程?这确实是他们解释的第一件事:你如何确定在
www.asdf.com/New York
中应该使用?city=
,在www.asdf.com/USA
中应该使用?country=
?这就是我感到困惑的地方。那么,你可以列举所有的国家吗?这意味着什么去列举所有的国家@Zerkmsis你用的这个类不是:[a-zA-Z0-9-]
相当于[\w-]
?…我想你是对的。