1

Ive been trying to get my sites htacess to provide effective rewrites for my filepages but im doing something wrong. My directory structure is very simple. All my files are in the root folder. So far my htacess looks like this.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-page.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example-page.com
    

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule   /front    /front_page.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule   /redirect    /redirect-page.php

This is working when im calling the page like "www.example-page.com/front_page.php (as it would anyway since the file is in the root folder). However the rewrite rules are not working and www.example-page.com/front (and all the rest) are giving me 404 errors. I know this format can work or something very similar to it as ive used it before on other sites. Im quite confused. Does somebody know what im doing wrong?

1 Answers1

0

Write the directives like this instead:

RewriteEngine on

RewriteRule ^front$ /front_page.php [L]

RewriteRule ^redirect$ /redirect-page.php [L]

There doesn't seem to be a need for all your additional conditions? I assume you only have the one domain example-page.com and you don't have a file called /front etc.

In .htaccess, the URL-path matched by the RewriteRule pattern does not start with a slash. You should also include start/end-of-string anchors on the regex so that you only match front exactly and not match it anywhere in the URL-path.

MrWhite
  • 12,647
  • 4
  • 29
  • 41