.htaccess中具有特殊字符

问题描述:

我想通过htaccess的做重定向:.htaccess中具有特殊字符

旧网址:

http://www.website.com/?p=5729 

新网址:

http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html 

所以我这样做htaccess的:

redirect 301 /?p=5729 http://www.website.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html 

但它没有不工作,可能是因为特殊的性格。

有人作为一个想法?

*****编辑***********

这里是htaccess文件:

# ~~start~~ Do not remove this comment, Prestashop will keep automatically 
the code outside this comment when .htaccess will be generated again 
# .htaccess automaticaly generated by PrestaShop e-commerce open-source 
solution 
# http://www.prestashop.com - http://www.prestashop.com/forums 

<IfModule mod_rewrite.c> 
<IfModule mod_env.c> 
SetEnv HTTP_MOD_REWRITE On 
</IfModule> 

RewriteEngine on 


#Domain: www.charlieetjune.com 
RewriteRule . - [E=REWRITEBASE:/] 
RewriteRule ^api$ api/ [L] 

RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 
[QSA,L] 

# Images 
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ % 
{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L] 
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ % 
{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ % 
{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L] 
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L] 
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L] 
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L] 
# AlphaImageLoader for IE and fancybox 
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L] 

# Dispatcher 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L] 
</IfModule> 

AddType application/vnd.ms-fontobject .eot 
AddType font/ttf .ttf 
AddType font/otf .otf 
AddType application/x-font-woff .woff 
<IfModule mod_headers.c> 
<FilesMatch "\.(ttf|ttc|otf|eot|woff|svg)$"> 
    Header set Access-Control-Allow-Origin "*" 
</FilesMatch> 
</IfModule> 

#If rewrite mod isn't enabled 
ErrorDocument 404 /index.php?controller=404 

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again 
RewriteCond %{THE_REQUEST} /\?p=5729 
RewriteRule ^$ http://www.charlieetjune.com/jmsblog/notrevie/18_charlie-raconte-les-chaussettes-qui-puent.html? [L,R] 

使用重定向指令查询字符串不能重定向。您需要使用以下规则:

RewriteEngine on 
RewriteCond %{THE_REQUEST} /\?p=5729 
RewriteRule ^$ http://example.com/path/? [L,R] 

不要忘了包括在目标网址的末尾,因为它会删除旧的查询字符串。

+0

它不起作用。我编辑完整的htaccess文件的帖子,也许它会帮助 –

+1

嗨Vincent.j你需要把它放在你的htaccess的顶部之前其他rewriteRules。 – starkeen

+1

是啊!它的工作原理,谢谢 –