0

I have a VirtualHost setup like this :

Alias /somedir /some/other/dir

http://example.com/somedir works fine

However, I need to setup mod_rewrite for /somedir (a CodeIgniter app for which I want clean URLs). Here's the bit from the CodeIgniter wiki :

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Usually, when mod_rewrite is used in subdirs changing RewriteBase to match the name of the dir is enough to make it work :

RewriteBase /somedir

...but it doesn't seem to work with mod_alias (getting 404s). Is there a workaround for this problem ?

Wrikken
  • 69,272
  • 8
  • 97
  • 136
Andrei
  • 1,606
  • 4
  • 19
  • 31
  • On a side note: when including mock-urls, use example.com as the domain name, that's what it is for. I doubt you are the owner of site.com :) – Wrikken Jul 25 '10 at 19:07
  • Where have you defined your `mod_rewrite` rules? – Tim Stone Jul 25 '10 at 19:09
  • @Wrikken ups...my bad, thanks for correcting that :). @Tim, in a `.htaccess` file at the root of the aliased dir. I've also tried setting them in the vhost config file, with the same effects. – Andrei Jul 25 '10 at 19:34

2 Answers2

0

The following worked on my test server, so trying this might solve your problem..

In your virtual host:

Alias /somedir /some/other/dir

RewriteEngine On

# I think these conditions should work correctly; the other ones shouldn't
# because the alias has not been applied at this stage of processing yet
RewriteCond /some/other/dir%{REQUEST_URI} !-d
RewriteCond /some/other/dir%{REQUEST_URI} !-f
# L is unnecessary in this context, but be sure to PT so mod_alias picks up
# on the rewrite
RewriteRule ^/somedir/(.*)$ /somedir/index.php/$1 [PT]
Tim Stone
  • 19,119
  • 6
  • 56
  • 66
  • Thanks, but it's still not working... I've tried putting it in `.htaccess`, at the root of the aliased dir, in a `` block in the vhost config, still no go. – Andrei Jul 26 '10 at 10:58
  • Did you try putting it in the vhost config outside of any ``/`` blocks? I'll test with the `.htaccess` later though and see if I can figure out why that might not be working either. – Tim Stone Jul 26 '10 at 17:19
0

Although I haven't tested your sample, in my own configurations, I haven't had much success with the PT flag, perhaps because of interactions with re-write rules in my config.

I've found it easier to restrict my use of aliases to the rewrite conditions, and always use the a file system path in the rewrite output.

Define SOME_DIR = "/somedir"
Define SOME_OTHER_PATH = "/some/other/dir"

Alias "${SOME_DIR}" "${SOME_OTHER_PATH}"

RewriteEngine On
RewriteCond ${SOME_DIR}%{REQUEST_URI} !-d
RewriteCond ${SOME_DIR}%{REQUEST_URI} !-f

RewriteRule ^${SOME_DIR}/(.*)$ ${SOME_OTHER_PATH}/index.php/$1 [NC,QSA,L]
compound eye
  • 1,898
  • 18
  • 23