繁体   English   中英

URL重写不起作用(ubuntu13.10 / apache2.4.6)

[英]URL Rewriting not working (ubuntu13.10/apache2.4.6)

我需要你的帮助! (对不起,我的英语不好)

我尝试在Ubuntu13.10 / Apache2.4.6上的本地主机中进行URL重写...我在互联网上搜索了很多时间,问题始终在这里。

这是我的.htaccess(我从URL重写开始,所以我不知道是否可以):

RewriteEngine On
AllowFromAll All
RewriteRule home/   index.php?uc=home

当我转到127.0.0.1/mywebsite/home/ ,出现404错误。

  • 我的.htaccess位于:mywebsite / .htaccess
  • 我用“ sudo a2enmod rewrite”激活了URL重写并重新启动了Apache。
  • 我在Apache日志中没有错误
  • 我读了解决方案的人说我必须将/ etc / apache2 / sites-available / default中的AllowOverride更改为On,但我没有/ etc / apache2 / sites-available / default文件
  • 我搞不清楚了...

拜托,我不知道该怎么办...

经过多次测试:我认为我遇到了AllowOverride问题

您要么需要指定RewriteBase

RewriteBase /mywebsite/
RewriteRule home   index.php?uc=home [L]

或将其添加到您的规则中

RewriteRule /mywebsite/home   index.php?uc=home [L]

我认为这更像是这样:

RewriteRule是相对于RewriteBase的,因此,如果您的.htacess位于/ mywebsite /文件夹中:

RewriteBase /
RewriteRule /home   index.php?uc=home [L]

这样就可以了,让我知道;)

所以...如果这不起作用,让我们从头开始。

查找httpd.conf

LoadModule rewrite_module libexec/mod_rewrite.soAddModule mod_rewrite.c应该在其中,并且不带注释标记(#)

在您的.htaccess中,有:

# The server must follow symbolic links (this can help in some apache versions)
Options +FollowSymlinks

# RewriteEngine activation
RewriteEngine on

# RewriteRule
RewriteRule ^home$   index.php?uc=home [L]

此配置适用于我的Apache 2.2.22。

事实是

/index.php?uc=home [L]

指向http://127.0.0.1/index.php

而不是http://127.0.0.1/mywebsite/index.php

由于DocumentRoot属性。 在真实域中,或/ wa virtualhost指向/index.php?uc=home [L]应该可以工作。

请记住,RewriteRule是相对于DocumentRootRewriteBase无法解决此问题。

暂无
暂无

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

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