MOD_REWRITE 帮助!

发布于 2024-08-31 08:32:53 字数 447 浏览 2 评论 0原文

我想使用模式重写来显示以下内容: mydomain.com/Florida/Tampa/ 而不是 mydomain.com/place.php?state=Florida&city=Tampa

我已经这样做了:(因为我认为这可能会有所作为!) mydomain.com/[name].html 而不是 mydomain.com/profile?user=[name]

这是代码!

Options +FollowSymLinks  
Options +Indexes 
RewriteEngine On 

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

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残疾 2024-09-07 08:32:54

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

# 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]

这里我使用 [^/]+(除 / 之外的一个或多个任意字符)。但是,如果您只想允许特定字符,则应该在您的模式中反映这一点(例如,请参阅 webdestroya 的提案)。

您还应该确保使用明确的 URI。在考虑规则之前,您应该开发一个精心设计的 URI 结构。您知道,酷 URI 不会改变

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.

赢得她心 2024-09-07 08:32:54

添加:

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

Add:

RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/ place.php?state=$1&city=$2 [L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文