3

I want to use .htaccess to rewrite url to my webite:

If url is http://mydomain.com or http://mydomain.com/ the index.html will serve the request, all other urls will go to index.php

please help!

2 Answers 2

5

Something like this would internally redirect any request with no path or only a trailing slash to index.html, and everything else to index.php with the path as an argument.

RewriteEngine  on
RewriteRule ^$ index.html
RewriteRule ^(.*)$ index.php?$1 [L]
Sign up to request clarification or add additional context in comments.

Comments

3

Quite simple, in two rules. One rule for the root (^$, which matches the empty string after the leading REQUEST_URI slash), and the rest for all other routes ((.+), which matches one or more characters):

RewriteRule ^$ index.html [L]
RewriteRule (.+) index.php [L]

Note: the leading slash does not appear in the source pattern. This is why the first rule checks for an empty string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.