.htaccess rules to rewrite URLs to front end page?
- by Dizzley
I am adding a new application to my site at example.com/app. I want views at that URL to always open myapp.php.
E.g.
example.com/app -> example.com/app/myapp.php and
example.com/app/ -> example.com/app/myapp.php
What's the correct form of rewrite rules in the .htaccess file?
I've got:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/
RewriteRule ^myapp\.php$ - [L]
RewriteRule ^myapp.php$ - [L]
RewriteRule . - [L]
</IfModule>
...based on what the Wordpress front-end does. But all I see at example.com/app is a directory of files. :(
(I put those rewrites at the top of my .htaccess file).
Any ideas?
Update
What actually worked:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/app(/.*)?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /app/myapp.php [L]
This is good because:
Explicit or implicit calls to app/myapp.php work.
example.com/app redirects to app/myapp.php
example.com/app/ redirects to app/myapp.php
example.com/app/subfunction redirects to app/myapp.php
All other calls to example.com/otherstuff are untouched.
Item 4 is Wordpress-like Front Controller pattern behaviour.
I think that rule
RewriteCond %{REQUEST_URI} ^/app.*$ [NC]
needs refining as it allows /app-oh-my-goodness etc. through too.
Thanks for the answers.