大网数据广告活动
服务器运维问答

Apache2 mod_rewrite + userdir

· 52CE 我爱测

I have an Ubuntu Server (web) with the following configuration Version: 13.10 Installed: Apache2, apache2 utils, php5 Enabled: rewrite, userdir Problem When I try to use rewrite rules, for example foo.bar.com/~«user»/page , I get…

问题原文

原帖链接 · erdemkeren · CC BY-SA 3.0

I have an Ubuntu Server (web) with the following configuration

  • Version: 13.10
  • Installed: Apache2, apache2 utils, php5
  • Enabled: rewrite, userdir

Problem

When I try to use rewrite rules, for example foo.bar.com/~«user»/page, I get

The requested URL /home/«user»/public_html/page.php was not found on this server.

As far as I know it is there; when I visit foo.bar.com/~«user»/page.php; tada! it is there.

I read all my configurations under /etc/apache2/apache2.conf, /etc/apache2/mods-available/userdir.conf but nothing seemed strange to me.

Additional Information

Permissions for user foder: drwx r-x r-x

Permissions for public_html drwx r-x r-x

I read I have to provide rewrite base but I really don't see anything strange with the path

What do I miss?


Rewrite Rules:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Or

RewriteRule ^login/?  login.php [L]

By the way, I tried to move the directory to /var/www and rewrite rules are operational now without 404 errors.

已采纳解答

原帖链接 · Giacomo1968 · CC BY-SA 3.0

You don’t seem to have a RewriteBase set, so it is most likely defaulting to:

RewriteBase /

So if you want to use it for userdir perhaps you should change your rewrite rules in your Apache config file—in apache2.conf or httpd.conf—to be like this:

RewriteEngine on
RewriteBase /~username/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-11-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。