简体   繁体   中英

htaccess impossible to remove index.php?page= tried 5 codes

My php code:

<?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";
                }
            ?>

I want remove from my url "index.php?page="

My links now look like this:

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

I want my links to look like this:

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

All codes wchich tried and didnt work:

Code 1:

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

Code 2:

RewriteEngine On

RewriteBase /

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

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

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

Code 3:

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

Code 4:

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

Other codes

what am i doing wrong?

The first part is

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

I removed the ampersand. This will work for site1 and site2.

I will update it for the second case when I get up

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM