【问题标题】:.htaccess working on windows however not working on apache2 in ubuntu.htaccess 在 Windows 上工作,但在 ubuntu 中不能在 apache2 上工作
【发布时间】:2014-09-08 06:53:30
【问题描述】:

我在 Windows 上的 XAMPP 中使用以下 htaccess 代码,它工作正常。但是,相同的代码在 Ubuntu Apache2 上不起作用,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?cmd=$1&caseSno=$2 [NC,L]
RewriteRule ^([^/\.]+)/?$ /?cmd=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/?$ /?cmd=$1 [NC,L]

没有 .htaccess 文件,我正在使用这样的网站链接:

http://localhost/index.php?cmd=home

哪个工作正常。

但在使用 .htaccess 文件作为上述代码后,我已将链接更改为:

http://localhost/home

但在 ubuntu 中,这些规则不起作用。 任何帮助将不胜感激。

【问题讨论】:

  • 定义“不起作用”。
  • 你收到 404 了吗?
  • 是,未找到 在此服务器上未找到请求的 URL /causeList。 Apache/2.4.7 (Ubuntu) 服务器在 localhost 端口 80
  • 是否启用了 mod_rewrite?还要检查 Apache conf 上的 AllowOverride 指令设置。

标签: php mysql apache .htaccess ubuntu


【解决方案1】:

您可以执行以下操作: [在你的终端上写下以下命令]

sudo nano /etc/apache2/apache2.conf

Check your file if there  is any # sign before the 

AccessFilename .htaccess

去掉#号。

转到以下并将 None 更改为 All

<directory /var/www/> 
   Options Indexes FollowSysLinks
   AllowOeverride None
   Require all granted
</directory>

替换

**AllowOverride None** to **AllowOverride All"

这就是你所做的一切。

【讨论】:

  • 是的,当然还要检查您是否启用了 mod_rewrite。然后在完成上述操作后,您必须重新启动您的 apache 服务
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-13
  • 2017-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多