开发者

MOD_REWRITE HELP!

I want to use mode rewrite to display the following: mydomain.com/Florida/Tampa/ instead of mydomain.com/place.php?state=Florida&city=Ta开发者_如何转开发mpa

I've akready done this: (since I think it might make a difference!) mydomain.com/[name].html instead of mydomain.com/profile?user=[name]

Here is the code!

Options +FollowSymLinks  
Options +Indexes 
RewriteEngine On 

RewriteBase /  
RewriteCond %{SCRIPT_FILENAME}! !-f  
RewriteCond %{SCRIPT_FILENAME}! !-d  
RewriteRule (.*).html profile.php?user=$1 [QSA.L]


You should make your patterns as specific as possible. So try these rules:

# stop rewriting process if request can be mapped to file or directory
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# get user pages
RewriteRule ^([^/]+)\.html$ profile.php?user=$1 [L,QSA]

# get paces
RewriteRule ^([^/]+)/([^/]+)/$ place.php?state=$1&city=$2 [L,QSA]

Here I use [^/]+ (one or more arbitrary characters except /). But if you only want to allow specific characters, you should reflect that in your patterns (see for example webdestroya’s proposal).

And you should also make sure that you use unambiguous URIs. You should develop a well-wrought URI structure before thinking about rules. You know, Cool URIs don’t change.


Add:

RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/ place.php?state=$1&city=$2 [L,QSA]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜