繁体   English   中英

.htaccess重写规则不起作用

[英].htaccess rewrite rules doesn't work

一个简单的问题,但目前我还不了解htaccess ...,所以希望您能对我有所帮助。

这是我的.htaccess文件:

#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]

在旧服务器上,它仅适用于第一部分。 因此,如果我这样打开url:如果没有index.php,test.com / foo / bar bar.php就会打开。 如果我这样打开url:test.com/foo/bar/25/3 25和3 ist in $_GET['page']

我用谷歌搜索了东西,发现了第二部分,但是它不起作用。 他告诉我他将打开bar.php,但在服务器上找不到此文件。 如果我在文件夹中查找文件。

希望有人可以帮助,非常感谢。

编辑:

新问题,.htaccess可以正常工作,但是如果我在侧面登录,我将重定向到目录test.com/foo/logged ...,这里有一个新的复杂菜单。

首先我将我的$_GET分成两部分:

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

这是日志/ index.php:

<?php if( $_SESSION) : ?>

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

<?php else : ?>

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

<?php endif; ?>

这是我的start.php:

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

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

<?php else: ?>

<? include "games.php"; ?>

<? endif; ?>

现在,如果我在登录区域中,则无法打开任何菜单链接,例如:foo / bar。 start.php中的链接现在必须看起来是: packages/foo/view/bar.php

但该网站始终与logging / index.php相同...

规则如下:

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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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