.htaccess删除index.php删除查询并保留字符串

时间:2013-11-13 21:21:41

标签: php apache .htaccess mod-rewrite

我一直在研究.htaccess文件。我开始的网址是,www.example.com/index.php?page=pagetitle。我希望链接仅显示www.example.com/pagetitle

到目前为止,我的.htaccess文件中唯一删除了index.php

Options -MultiViews

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.(php|html?)
RewriteRule ^ /%1 [R=301,L]

非常感谢任何帮助,遗憾的是我没有自己创建这些代码的知识。

提前谢谢。

我还将编辑这个问题,因为我从其他人的支持等方面更多地了解这个问题。

1 个答案:

答案 0 :(得分:2)

您可以尝试以下规则:

Options -MultiViews

RewriteEngine on

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]