问题原文
原帖链接 · 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.phpwas 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
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
