Regex htaccess重写url名称

Regex htaccess重写url名称,regex,.htaccess,mod-rewrite,Regex,.htaccess,Mod Rewrite,我已经为这件事伤心了将近两个小时了 我有一个网站(我们叫它example.com) 我需要重写这个url: example.com/plant.php?naam=Brahea%20Armata 到 example.com/Brahae_Armata 这是我的.htaccess文件的外观: RewriteEngine On RewriteCond %{HTTP_HOST} example.com/plant.php?naam=$ [NC] RewriteRule ^(.*)$ http://exa

我已经为这件事伤心了将近两个小时了

我有一个网站(我们叫它example.com) 我需要重写这个url:

example.com/plant.php?naam=Brahea%20Armata

example.com/Brahae_Armata

这是我的.htaccess文件的外观:

RewriteEngine On
RewriteCond %{HTTP_HOST} example.com/plant.php?naam=$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

那不行。有人知道问题出在哪里吗?

您可以在root.htaccess中使用这些规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} /plant\.php\?naam=(.*)\%20(\S*)\sHTTP [NC]
RewriteRule ^ /%1_%2? [NE,R=301,L]

RewriteCond %{THE_REQUEST} /plant\.php\?naam=(.*)\sHTTP [NC]
RewriteRule ^ /%1? [NE,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) page.php?name=$1 [QSA,L]

URL中是否可以有多个
%20
?不,我认为在一个URL中不会有两个空格。有些页面的URL中不包含空格。使用以下代码是否正确?RewriteCond%{THE_REQUEST}/plant\.php\?naam=(.*)\sHTTP[NC]RewriteRule^/%1?[NE,R=301,L]