mod_rewrite的帮助! [英] MOD_REWRITE HELP!

查看:182
本文介绍了mod_rewrite的帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用模式改写,显示如下: 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]
 

解决方案

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

 #停止重写的过程,如果请求可以被映射到文件或目录
的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.

这篇关于mod_rewrite的帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆