删除.php和问号并用斜杠替换 - .htaccess URL重写

时间:2017-03-24 15:14:30

标签: php apache .htaccess url-rewriting

在这里,我使用以下.htaccess重写规则。

Options +FollowSymLinks -MultiViews

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain1.com$ [NC] 
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [L,R=301] 

RewriteRule ^index.php$ http://www.domain1.com/ [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php [NC]
RewriteRule ^ /%1 [QSA,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ /$1.php

</IfModule>

我需要转换:

1- domain1.com => http://www.domain1.com/
2- domain1.com/whatever.php => http://www.domain1.com/whatever
3- domain1.com/whatever.php?whatever-whatever 
=> http://www.domain1.com/whatever/whatever-whatever
4- domain1.com/whatever.php?whatever1=whatever-whatever2 
=> http://www.domain1.com/whatever/whatever1/whatever-whatever2

#1和#2成功实现,但经过多次#3和#4的重写规则后无法实现。

Rightnow,上面附上.htaccess重写规则给出了结果:

1- http://www.domain1.com 
(Correct for non-www to www)

2- http://www.domain1.com/whatever 
(Correct for removing .php from FILENAME)

3- http://www.domain1.com/whatever?whatever-whatever 
(Wrong for not removing question mark(?) and replace with slash(/))

4- (Not Achieve)

请建议。

0 个答案:

没有答案