在mod_rewrite的URL中的特殊字符特殊字符、mod_rewrite、URL

2023-09-02 20:34:55 作者:我命由我不由天

我希望这个网址:

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

要改写为这一个:

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

我用这mod_rewrite的规则,在我的.htaccess做到这一点

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

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

但是,结果并不像我想的那样,当我去的第一个URL,我得到一个网页未找到消息。

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/

我应该让我的.htaccess什么修改,使这项工作?

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

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

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]