简体   繁体   English

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

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

I need your help! 我需要你的帮助! (sorry for my bad english) (对不起,我的英语不好)

I try to do url rewriting in my localhost on Ubuntu13.10/Apache2.4.6 ... I searched a lot of time on internet and problem is always here.. 我尝试在Ubuntu13.10 / Apache2.4.6上的本地主机中进行URL重写...我在互联网上搜索了很多时间,问题始终在这里。

this is my .htaccess (I begin in url rewriting so I don't know if it's ok) : 这是我的.htaccess(我从URL重写开始,所以我不知道是否可以):

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

and when I go to 127.0.0.1/mywebsite/home/ I have a 404 error. 当我转到127.0.0.1/mywebsite/home/ ,出现404错误。

  • My .htaccess is in : mywebsite/.htaccess 我的.htaccess位于:mywebsite / .htaccess
  • I activated url rewrite with "sudo a2enmod rewrite" and restarted apache. 我用“ sudo a2enmod rewrite”激活了URL重写并重新启动了Apache。
  • I have no error in apache logs 我在Apache日志中没有错误
  • I read solution who said I have to change AllowOverride to On in /etc/apache2/sites-available/default but I dont have /etc/apache2/sites-available/default file 我读了解决方案的人说我必须将/ etc / apache2 / sites-available / default中的AllowOverride更改为On,但我没有/ etc / apache2 / sites-available / default文件
  • I am lost... 我搞不清楚了...

Please, I don't know what to do... 拜托,我不知道该怎么办...

After many tests : I think I have a problem of AllowOverride 经过多次测试:我认为我遇到了AllowOverride问题

You either need to specify the RewriteBase 您要么需要指定RewriteBase

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

or add it to your rule 或将其添加到您的规则中

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

I think this is more like this : 我认为这更像是这样:

RewriteRule is relative to the RewriteBase, so if your .htacess is in /mywebsite/ folder : RewriteRule是相对于RewriteBase的,因此,如果您的.htacess位于/ mywebsite /文件夹中:

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

this way it should work, let me know ;) 这样就可以了,让我知道;)

So... If this is not working, let's start by the beginning. 所以...如果这不起作用,让我们从头开始。

Find httpd.conf 查找httpd.conf

LoadModule rewrite_module libexec/mod_rewrite.so and AddModule mod_rewrite.c should be in there, and without comment mark (#) LoadModule rewrite_module libexec/mod_rewrite.soAddModule mod_rewrite.c应该在其中,并且不带注释标记(#)

In your .htaccess, there is : 在您的.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]

This configuration works on my apache 2.2.22. 此配置适用于我的Apache 2.2.22。

The truth is that 事实是

/index.php?uc=home [L]

points on http://127.0.0.1/index.php 指向http://127.0.0.1/index.php

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

because of the DocumentRoot property. 由于DocumentRoot属性。 On a real domain, or /wa virtualhost pointing on /mywebsite/, /index.php?uc=home [L] should work. 在真实域中,或/ wa virtualhost指向/index.php?uc=home [L]应该可以工作。

Keep in mind that RewriteRule is relative to the DocumentRoot and RewriteBase can't resolves this problem. 请记住,RewriteRule是相对于DocumentRootRewriteBase无法解决此问题。

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

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