2014-03-25 87 views
0

我有一个RewriteRule重新命名我的网址在我的网站,允许通过字母和空格。我想知道如何改变我的正则表达式,让单引号和句点通过URL。这是我的.htaccess:允许'和。通过URL .htaccess

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTPS}s ^on(s)| 
RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
RewriteRule ^(\w+)$ ./index.php?role=$1 
RewriteRule ^(\w+)/$ ./index.php?role=$1 
RewriteRule ^([\w]+)/([\w\s]+)&([\s\w]+)$ ./result.php?role=$1&champ1=$2&champ2=$3 
+3

你就像你的第8行:'\ .'和'\'' – Martijn

+0

@Martijn所以底线看起来像:'RewriteRule ^([\ w] +)/([\ w \ s \。\'\ ] +)&([\ s \ w \'\。] +)$ ./result.php?role = $ 1&champ1 = $ 2&champ2 = $ 3'? – user1895377

+0

@ user1895377:这应该有效。如果不提供您想要匹配的示例URI。 – anubhava

回答

1

你逃脱他们,就像你的8号线:\.\'

另外,如果你添加一个问号,你可以删除线9:

# These two: 
RewriteRule ^(\w+)$ ./index.php?role=$1 
RewriteRule ^(\w+)/$ ./index.php?role=$1 
# Can be replaced by: 
RewriteRule ^(\w+)/?$ ./index.php?role=$1 

# And if I understand it properly, the last two lines don't happen both: 
# You can replace the bottom 3 lines with this: 
RewriteRule ^(\w+)/?$ ./index.php?role=$1 [L] 
RewriteRule ^([\w]+)/([\w\s]+)&([\s\w]+)$ ./result.php?role=$1&champ1=$2&champ2=$3