Apache .htacces url重写
我的userdir下有一个php/apache网站,比如Apache .htacces url重写,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我的userdir下有一个php/apache网站,比如http://localhost/~johnny5/ 我有一个/en文件夹,其中有一个.htaccess文件和一个index.php文件: /home/johnny5/public_html /somefile.php /someotherfile.php /en/
http://localhost/~johnny5/
我有一个/en
文件夹,其中有一个.htaccess
文件和一个index.php
文件:
/home/johnny5/public_html
/somefile.php
/someotherfile.php
/en/
.htacces
index.php
我在/en
下启用url重写,因此所有请求都由index.php处理。以下是.htacces的内容:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~johnny5/en
RewriteRule . index.php
到目前为止,一切正常。
当我点击时,说,http://localhost/~johnny5/en/foo/bar
,请求由/en/index.php
处理
现在,出于测试目的,我将站点移动到/var/www
下,这样我就可以通过http://localhost/
。我调整.htaccess
文件以删除用户文件夹:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /en
RewriteRule . index.php
我现在有了这个结构:
/var/www
/somefile.php
/someotherfile.php
/en/
.htacces
index.php
现在,如果我点击http://localhost/en/foo/bar
,我希望请求由/en/index.php
处理,但我得到的只是一个404,找不到/en/foo/bar
看起来重写模块在我的用户目录下工作,但不在“main”目录下工作。
我遗漏了什么?不确定您在服务器上的新结构,但请记住一条非常重要的规则: .htaccess规则仅适用于当前和子(递归)目录,不适用于高于.htaccess目录的目录 因此,如果您的.htaccess现在处于:
/home/johnny5/public_html/en/.htaccess
它不能与路径一起工作
http://localhost/en/foo/bar
如果您在服务器上的根目录是home/
尝试将您的htaccess移动到您的www服务器的根目录,然后重试,这都是我的错误-配置错误
我在错误的文件夹下“AllowedOverride”。我将
public\u html
下的整个结构移动到/var/www
下。但是我认为我的.htaccess根本没有执行,即使我在配置中允许它。也许配置有问题该死,我的错,这确实是一个配置错误,我“AllowOverride”在错误的文件夹下。我真丢脸+1.无论如何都需要帮助;)