MOD_REWRITE 帮助!
我想使用模式重写来显示以下内容: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使您的模式尽可能具体。因此,请尝试以下规则:
这里我使用
[^/]+
(除/
之外的一个或多个任意字符)。但是,如果您只想允许特定字符,则应该在您的模式中反映这一点(例如,请参阅 webdestroya 的提案)。您还应该确保使用明确的 URI。在考虑规则之前,您应该开发一个精心设计的 URI 结构。您知道,酷 URI 不会改变。
You should make your patterns as specific as possible. So try these rules:
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: