douzhaocheng4533 2017-03-24 15:14
浏览 133

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

Here, I am using following .htaccess Rewrite Rule.

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>

I need to convert:

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 and #2 are achieve successfully but after several trail of Rewrite Rules for #3 and #4 cannot achieve.

Rightnow, above attach .htaccess Rewrite Rules give Results:

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)

Kindly suggest.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办