Special characters in mod_rewrite url

只谈情不闲聊 提交于 2020-01-05 07:56:09

问题


I want this URL:

http://www.mydomainblabla.com/s/can+you+drill+shrinky+dinks?.html

to be rewritten to this one:

http://www.mydomainblabla.com/search.php?q=can+you+drill+shrinky+dinks?

I am using this mod_rewrite rule in my .htaccess to accomplish this

RewriteRule ^s/(.+).html$ search.php?q=$1 [L,QSA]

However, the result is not as I want it, when I go to the first url, I get a page not found message.

The same problem occurs when I visit this url:

http://www.mydomainblabla.com/s/http://www.zakgeldnodig.nl/.html

which should be rewritten into this one:

http://www.mydomainblabla.com/search.php?q=http://www.zakgeldnodig.nl/

What modifications should I make to my .htaccess to make this work?


回答1:


Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+s/(.+?)\.html [NC]
RewriteRule ^ search.php?q=%1 [L,NE]


来源:https://stackoverflow.com/questions/13145689/special-characters-in-mod-rewrite-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!