如何激活 mod_rewrite? [英] How to activate mod_rewrite?

查看:33
本文介绍了如何激活 mod_rewrite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过好几次了.但我无法让它工作.

I know that this question have been asked several times. But I can't get it to work.

我在我的 Ubuntu 服务器中安装了 Apache2 我还可以确认使用 phpinfo(); 安装了 mod_rewrite.我还在我的根文件夹(/var/www/.htaccess)中放置了一个名为 .htaccess 的文件.在我的 .htaccess 文件中,我粘贴了以下代码:

I installed Apache2 in my Ubuntu server I can also confirm that mod_rewrite is installed using phpinfo();. I have also put a file called .htaccess in my root folder(/var/www/.htaccess). In my .htaccess file I paste the following code:

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^.*$ test.php

所以一切都被重定向到 test.php

So everything is redirected to test.php

但是还是不行.所以我检查了/etc/apache2 下的 httpd.conf 文件.它完全是空的,没有代码行(这对我来说似乎有点奇怪)?!但是,检查 Stackoverflow 答案中的 httpd.conf 中至少应该有以下代码:

But it still doesn't work. So I checked my httpd.conf file under /etc/apache2. It is completely empty, with no lines of code (This seems a little odd to me)?! However checking in Stackoverflow answers there should be at least the following code in httpd.conf:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Satisfy all
</Directory>

所以我将该代码粘贴到 httpd.conf 中.并使用 sudo/etc/init.d/apache restart 重新启动 Apache.还是不行?

So I paste that code in httpd.conf. And restarted Apache with sudo /etc/init.d/apache restart. And it still does not work?

我还测试打开文件/sites-enabled/000-default 和/sites-available/default,其中所有虚拟主机设置都位于 /var/www 目录下并更改/ 到 AllowOverride All.mod_rewrite 仍然不起作用.谁能帮帮我吗.这个问题已经烤了我一段时间了.

I have also tested to open the file /sites-enabled/000-default and /sites-available/default, where all virtual host settings lies and change under the directory /var/www and / to AllowOverride All. The mod_rewrite still doesn't work. Can anyone please help me. This problem has been baking my nuts for a while.

另外,我的 apache2.conf 文件不起作用.我试着写些废话.它仍然给我正常的结果而不是 http 500 错误

Also, my apache2.conf file doesn't work. I tried to write som nonsense. And it is still gives me the normal result instead of http 500 error

推荐答案

Niels Bom 的所有建议都是最聪明的(我认为).但我会将此添加为第一个建议:尝试通过 Ubuntu 命令启动和停止 apache:然后当它应该停止时,确保它已停止,即验证您的本地页面不再显示.

All suggestions from Niels Bom are the smartest ones (I think). But I would add this as the first suggestion: try to launch and stop apache via the Ubuntu command: then when it's supposed to be stopped, make sure it's stopped ie verify your local page doesn't show anymore.

  • 阅读文件夹 /etc/apache2/ 中的内容.应该有 apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
  • 然后,如果一切正常,请查看 mods-enabled 在这里您会发现是否启用了 mods 如果是这样,那么您可以继续,否则请查看其他有关启用改写
  • 看看sites-enabled:在这里您可以找到...(猜猜是什么?)启用的网站.应该有 default 网站.
  • 如果是这样,打开这个文件,试着把apache的废话放进去,重启服务器,看看它是否开心.如果它不开心,那很好.如果它很高兴,那么你正在处理错误的文件
  • 最后:尝试检查此默认虚拟主机的htaccess 文件的授权是什么.这是它们的工作方式:如果 Apache 在 vhost 文件中找不到任何指令,它将应用全局配置.所以我建议在你的 vhost 文件中添加配置,在 <virtualhost> - </virtualhost> 标签之间(当然).
  • read what's in the folder /etc/apache2/. There should be apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
  • then if everything is ok, take a look at mods-enabled where you will find if the mods are enabled if so, then you can go on, otherwise take a look at the other answers about enabling modrewrite
  • take a look at sites-enabled: it's where you can find the sites that are... (guess what?) enabled. There should be the default website.
  • if so, open this file, and try to put apache nonsense in it, restart the server and see if it's happy or not. If it's not happy that's good. If it's happy then you're working on the wrong file
  • last: try to check what are the authorisations for htaccess files for this default vhost. Here's the way they work: if Apache doesn't find any directive in the vhost file, it will apply the global configuration. So I'd suggest to add the configuration in your vhost file, between the <virtualhost> - </virtualhost> tags (of course).

请告诉我发生了什么,我很乐意相应地更新我的问题.

Please tell me what's going on and I'd be glad to update my question accordingly.

这篇关于如何激活 mod_rewrite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆