anilCSE anilCSE - 3 months ago 18
Apache Configuration Question

How to create multiple rewrite rules in .htaccess

I want to have this kind of structure in .htaccess. Is it possible?



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^signup$ /signup.html [L]

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^signin$ /signin.html [L]

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^home$ /landing.html [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]
</IfModule>




For landing, signin, signup I want to request separate pages and for all other requests I need to request index.html page. Can I do that with .htaccess?

Answer

Have it like this:

DirectoryIndex index.html
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} /index\.html$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(signup|signin)/?$ $1.html [L,NC]

RewriteRule ^home/?$ landing.html [L,NC]

RewriteRule . index.html [L]