简体   繁体   中英

.htaccess rewrite rules doesn't work

simple question but at the moment i don't understand htaccess... so i hope you can help me.

this is my .htaccess file:

#RewriteEngine On

#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-l

#RewriteRule ^(.+)$ index.php?page=$1 [QSA]


RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ $1.php [L]

at the old server it works only with the first part. So if i open url like this: test.com/foo/bar bar.php would be open if there is no index.php. if i open url like this: test.com/foo/bar/25/3 25 and 3 ist in $_GET['page'] .

I googled somthing and found the second part, but it should not work. he told me that he would open bar.php but didn't find this on the server. If i look in my folder there is the file.

hope someone could help, thanks a lot.

EDIT:

New Problem, the .htaccess works well but if i logged in on the side, i would redirect to the directory test.com/foo/logged... there is a new complex menu.

first i have my $_GET splitted:

$url = explode("/", $_GET['page']);

and this is the logged/index.php:

<?php if( $_SESSION) : ?>

<?php include("start.php"); ?>

<?php else : ?>

<?php include(BASE_URL."/login.php"); ?>

<?php endif; ?>

this is my start.php:

<?php if( strlen($url[0]) > 0 ) : ?>

<?php include("packages/".$url[0]."/view/".$url[1].".php"); ?>      

<?php else: ?>

<? include "games.php"; ?>

<? endif; ?>

now, if i am in the logged area i can't open any menu-link like: foo/bar. the link in start.php have to look now so: packages/foo/view/bar.php .

but the site is allways the same as logged/index.php...

Have your rule like this:

DirectoryIndex index.php

RewriteEngine On
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/test/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

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