Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess Remove index.php删除查询并保留字符串_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

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

.htaccess Remove index.php删除查询并保留字符串,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我一直在处理一个.htaccess文件。我开始的url是,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?) RewriteRu

我一直在处理一个.htaccess文件。我开始的url是,
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]
任何帮助都将不胜感激,遗憾的是,我自己没有创建这些代码的知识

先谢谢你


当我从其他人的支持等方面了解更多信息时,我也将编辑此问题。

您可以尝试以下规则:

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]

看起来很有效,非常感谢!我会接受你的回答,当它让我:-)