3

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
  • 3,542
  • 27
  • 38
erdemkeren
  • 127
  • 1
  • 8

2 Answers2

4

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
Giacomo1968
  • 3,542
  • 27
  • 38
  • Thanks for your answer. But as I wrote in my question; I don't want to provide this information in .htaccess file. Isn't there any place where I can specify that, so every .htaccess file don't include that line. – erdemkeren Nov 12 '13 at 15:13
  • Who said this should be placed in an `.htaccess` file? Put it in the main Apache2 server config for the whole domain & you are done. – Giacomo1968 Nov 12 '13 at 15:59
  • I said I don't know where to place it. Thanks. – erdemkeren Nov 12 '13 at 17:21
  • Look in `/etc/apache2/apache2.conf` or `/etc/apache2/httpd.conf`. – Giacomo1968 Nov 12 '13 at 17:51
2

I found this on ubuntuforums.org:

RewriteBase /~username/

http://ubuntuforums.org/showthread.php?t=1196217

Alex
  • 346
  • 1
  • 8
  • Thanks for your answer. But as I wrote in my question; I don't want to provide this information in .htaccess file. Isn't there any place where I can specify that, so every .htaccess file don't include that line. – erdemkeren Nov 12 '13 at 15:13
  • So where do you have these rewrite rules? In userdir.conf? Try to add it in there I guess.. – Alex Nov 12 '13 at 15:42