.htaccess htaccess无法删除索引,php?page=已尝试5个代码

piah890a  于 2022-11-16  发布在  PHP
关注(0)|答案(1)|浏览(115)

我的php代码:

<?php $definedPages = array ( 'dir/site5', 'site1' );
                $page = (isset($_GET['page'])) ? $_GET['page'] : 'default.php';
                if(in_array($page, $definedPages)) {
                include "{$page}.php";
                } else {
                include "default.php";
                }
            ?>

我想从我网址中删除“index.php?page=”
我的链接现在如下所示:

example.pl/index.php?page=site1
example.pl/index.php?page=site2
example.pl/index.php?page=dir/site5
example.pl/index.php?page=dir/site6

我希望我的链接看起来像这样:

example.pl/site1
example.pl/site2
example.pl/dir/site5
example.pl/dir/site6

所有尝试但无效的代码:
代码1:

RewriteEngine On
RewriteRule ^(.*)$ index.php?page=$1&%{QUERY_STRING} [NC,L]

代码二:

RewriteEngine On

RewriteBase /

RewriteRule ^(Application|Library|Bin) - [F,L]

RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d

RewriteRule .* index.php?/page=$0 [PT,L]

代码三:

RewriteRule ^(.*)$ index.php?page=$1 [NC, QSA]

代码四:

RewriteCond %{THE_REQUEST} /index\.php\?page=([^&\s]+)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]
RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA,L,NC]

其他代码
我做错了什么?

drkbr07n

drkbr07n1#

第一部分是

RewriteEngine On
RewriteRule ^(.*)$ index.php?page=$1%{QUERY_STRING} [NC,L]

我删除了&号。这似乎适用于您的所有情况。

相关问题