Robiin
Robiin

Reputation: 11

RewriteRule rewrites to incorrect location

I'm using the Mod_Rewrite module to rewrite urls.

This is my RewriteRule:

RewriteRule ^index index.php
RewriteRule ^page page.php

If I'm going to localhost/page the content of page.php is shown. But when I go to localhost/index the url get rewritten to:

http://localhost/C:/Users/Username/Documents/Xampp/htdocs/index.php

Thank you.

Edit: The full .htaccess code:

RewriteEngine On
RewriteBase /
RewriteRule ^page page.php
RewriteRule ^index index.php
RewriteRule ^about about.php
RewriteRule ^contact contact.php

Upvotes: 1

Views: 54

Answers (2)

anubhava
anubhava

Reputation: 785128

Try these rules with anchors $:

RewriteEngine On
RewriteBase /

RewriteRule ^page/?$ page.php [L]
RewriteRule ^index/?$ index.php [L]
RewriteRule ^about/?$ about.php [L]
RewriteRule ^contact/?$ contact.php [L]

Alternatively you can try this line on top of your .htaccess:

Options +MultiViews

Upvotes: 0

Sumurai8
Sumurai8

Reputation: 20737

Problems like these are usually fixed by defining a RewriteBase (docs). Put the following directive after the RewriteEngine directive, but before any rule you have:

RewriteBase /

Upvotes: 0

Related Questions