I have the following directory structure for my local site.
mysite
|_ css
|_ images
|_ logo.png
|_ js
|_ app
|_ index.php
|_ .htaccess
I'm trying Apache URL rewriting to redirect to http://mysite.dev/app/index.php
for non-existing directories.
For example, http://mysite.dev/en/home
will be rewritten into http://mysite.dev/app/index.php
I have tried this rewrite rule in my .htaccess
file:
Options -Indexes
DirectoryIndex index.php index.html index.htm
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ app/index.php [L]
</IfModule>
But it is rewritten for all existing directories and no-existing directories.
That is, when I browse http://mysite.dev/mysite/images/logo.png
, it is rewritten to http://mysite.dev/mysite/app/index.php
I added the line above the two RewriteCond
lines, but it did not work.
RewriteRule ^(images|css|js) - [NC,L]
My goal is to skip the rule if any file or directory exists.
How can I write RewriteCond
and RewriteRule
for this purpose?
[Edit]
I found the problem. It is because of the virtual host I added for my site. I have the following lines of code in httpd-vhost.conf
:
<VirtualHost mysite.dev>
DocumentRoot "C:/xampp/htdocs/mysite"
ServerName mysite.dev
ServerAlias mysite.dev
<Directory "C:/xampp/htdocs/mysite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I browsed http://mysite.dev/images/logo.png
, the RewriteCond
is not working properly
But when I removed the virtual host and I browsed http://localhost/mysite/images/logo.png
, it is working fine and I see the image correctly.
I'm not sure what is the problem and conflict of virtual host and RewriteCond
.