SvennD
mod_rewrite and userdir for Apache2 on chromebook
August 6, 2015

mod_rewrite and userdir for Apache2 on chromebook

Posted on August 6, 2015  •  1 minutes  • 192 words  •  Suggest Changes

I wanted to get mod_rewrite to work, to get a nice looking url, even tho it is only development version here on my chromebook. (using crouton) While mod_rewrite is easy enough, getting it to work on the mod_userdir was a bit more tricky.

Getting mod_rewrite activated is easy :

# activate the module
sudo a2enmod rewrite

# edit your sites (or in my case the default)
sudo nano /etc/apache2/sites-enabled/000-default

# search and set AllowOverride from none to all
AllowOverride All

# restart the server
sudo service apache2 restart

Sadly this will break most copy-paste mod_rewrite rules, also this one :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

This won’t work, cause the “variable” RewriteBase is not given and the default / will send you to the /var/www (default) where nothing is, resulting in a 404 (unless something is there, -unlikely-)  Fixing it, is a simple as setting your base path. Note that for me, the files where not in the root of my home directory ( /home/svenn/Downloads/my_project_dir/)  for those setting see  this post.

 

RewriteEngine on
RewriteBase /~svenn/my_project_dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Support

If you enjoyed this website, consider buying me a Dr. Pepper

Buy me a Dr PepperBuy me a Dr Pepper