Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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 主页+;从GET参数重定向值_.htaccess - Fatal编程技术网

.htaccess 主页+;从GET参数重定向值

.htaccess 主页+;从GET参数重定向值,.htaccess,.htaccess,我需要在我的网站上打开file.php作为索引。主页上的将打开file.php,无需重定向到www.website.com/file.php 第二个重写规则是将www.website.com/?id={id}重定向到www.website.com/{id} RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ file.php?id=

我需要在我的网站上打开
file.php
作为索引。主页上的将打开
file.php
,无需重定向到
www.website.com/file.php

第二个重写规则是将
www.website.com/?id={id}
重定向到
www.website.com/{id}

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ file.php?id=$1
RewriteRule ^$ /file.php

RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]*)(&.*)?$
RewriteRule ^ %{REQUEST_URI}?%1%2%3

帮助我使用htaccess代码?

您可以使用如下规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+\?id=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteRule ^$ /file.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ file.php?id=$1 [L,QSA]

重写规则^page/%1?[R=301,L,NE]
-->
重写规则^/%1?[R=301,L,NE]
…但这正是我需要的是,很抱歉,
/page
是一个输入错误,因为我在本地apache上测试它。没关系,我立即知道“问题”在哪里-只是更正:)