重写URL以htaccess的 [英] rewrite url with htaccess
问题描述
首先我是一个初学者,请详细回答。
First of all I am a beginner so please answer in details.
我的问题:我想写一个.htacess规则。
My Problem: I want to write a .htacess rule for.
www.asdf.com/city.php?city=New-York to www.asdf.com/New-York
也与我有其他的页面,如
but also with that I have other pages such as
www.asdf.com/country.php?country=USA
我想显示为
www.asdf.com/USA and
www.asdf.com/state.php?country=LA
我想显示为
www.asdf.com/LA
pretty的困惑该怎么做,任何帮助,我真的需要理清了这一点。
Pretty confused how to do that, any help, I really need to sort this out.
在此先感谢
推荐答案
林不知道我的做法是做到这一点的最好办法,但是这是我如何做它的那一刻:
Im not sure my approach is the best way to do it but this is how I'm doing it at the moment:
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?var1=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?var1=$1
把所有的页面到的index.php
Rewrites all pages to the index.php
在的index.php我得到的网址:$网址= $ _ SERVER [REQUEST_URI]; 然后,我做一个MySQL查询,以确定它是什么样的页面。
On index.php I get the URL with: $url = $_SERVER["REQUEST_URI"]; Then I do a MYSQL search to determine what kind of page it is.
switch($pagetype){
case "city": include('city.php');
break;
case "country": include('country.php');
break;
}
这篇关于重写URL以htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!