1

I have the following in my .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ _service.php?uri=$1 [NC,L]
</IfModule>

Only problem is there is no rewrite happening and I simply see a directory listing when attempting to access the root page of the server localhost.

Even when I try to make the match optional RewriteRule ^(.*)?$ _service.php?uri=$1 [NC,L] it does not work.

The rewrite seems fine for any other case e.g. localhost/foo/bar

How do I get the rewrite to happen for this particular case?

samazi
  • 1,161
  • 12
  • 24
  • 2
    What do you want to proxy to when user is accessing root dir? For example, localhost/foo/bar will proxy to service.php?uri=foo/bar, so should root go to uri=/ . Simple way to proxy root is to hardcode RewriteRule ^$ _service.php?uri=/ – Boris Feb 26 '15 at 04:56

2 Answers2

1

The problem is that the root is a directory. So this condition is preventing your rule from getting applied:

RewriteCond %{REQUEST_FILENAME} !-d

Try adding a rule like:

RewriteRule ^$ _service.php?uri=/ [NC,L]

or something

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
1

You might need to specify the document root in order for the file or directory to be found; my variation on this pattern is:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteRule . /index.php [L,QSA,B]

The root page is served correctly (for me) in this case (e.g. http://www.example.com/). NB, I have this in vhost.conf and not in a .htaccess.

Coder
  • 2,833
  • 2
  • 22
  • 24