2014-03-25 131 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