mod_rewrite的帮助!mod_rewrite

由网友(敢作敢当的小侽人)分享简介:我想用模式改写,显示如下:mydomain.com/Florida/Tampa/而不是mydomain.com/place.php?state=Florida&city=Tampa的我akready做到了这一点:(因为我想可能有所作为!)而不是mydomain.com/profile?user=[name mydo...

我想用模式改写,显示如下: mydomain.com/Florida/Tampa/而不是mydomain.com/place.php?state=Florida&city=Tampa的

我akready做到了这一点:(因为我想可能有所作为!) 而不是mydomain.com/profile?user=[name mydomain.com/[name].html]

下面是code!

 选项+了FollowSymLinks
选项​​+指标
RewriteEngine叙述上

的RewriteBase /
的RewriteCond%{} SCRIPT_FILENAME! !-F
的RewriteCond%{} SCRIPT_FILENAME! !-d
重写规则(。*)。HTML profile.php?用户= $ 1 [QSA.L]
 

解决方案 坎巴拉太空计划v1.4.1MechJeb2汉化mod下载 坎巴拉太空计划mod下载

您应该让你的模式尽可能具体。因此,尝试以下规则:

 #停止重写的过程,如果请求可以被映射到文件或目录
的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^  -  [L]

#获得用户页面
重写规则^([^ /] +)。HTML $ profile.php?用户= $ 1 [L,QSA]

#得到步伐
重写规则^([^ /] +)/([^ /] +)1 / $ place.php状态= $&放大器;城市= $ 2 [L,QSA]
 

下面我用 [^ /] + (除 / 一个或多个任意字符)。但是,如果你只希望允许特定的字符,你应该反映在你的模式(例如,见 webdestroya的建议)。

而且你还要确保你使用明确的URI。想着规则之前,您应该制定一个良好的锻造URI结构。要知道,的酷的URI不要更改的。

I want to use mode rewrite to display the following: mydomain.com/Florida/Tampa/ instead of mydomain.com/place.php?state=Florida&city=Tampa

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.

阅读全文

相关推荐

最新文章