Joel Murphy
Joel Murphy

Reputation: 2512

Repeatedly appended URLs after RewriteRule in .htaccess?

This is my first time re-writing urls to be SEO friendly.

Here's my htaccess rule:

RewriteEngine On
RewriteRule ratings/ ratings.php
RewriteRule regions/ regionlist.php
RewriteRule mobile/ mobile.php

For some reason, when I click the same link twice, the url will append itself in the address bar. Heres a gif image showing this happening:

https://i.sstatic.net/y5hqA.gif

Is this bad? If it is, does anyone know what's wrong ?

Help would be greatly appreciated!

Thanks everyone

Upvotes: 3

Views: 245

Answers (4)

onatm
onatm

Reputation: 846

Change your RewriteRules to this:

RewriteRule ^([a-zA-Z]+)$ $1.php

and make sure that your links to be like this:

<a href="/ratings">ratings</a>

but if you need specific rewrites change the location of slash

RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php

Upvotes: 3

Moyshe
Moyshe

Reputation: 1122

I think it's not the htaccess which couses trouble here... IMO you take current URL and append clicked item's name. Create the URL from scratch instead.

Upvotes: 1

Austin S.
Austin S.

Reputation: 304

if you want the rewrite to always be based off the root directory you may want to write your rules with a preceeding "/"(slash)

RewriteEngine On
RewriteRule /ratings ratings.php
RewriteRule /regions regionlist.php
RewriteRule /mobile mobile.php

This should force the rewrite rule to append this to the root url.

Upvotes: 0

jschorr
jschorr

Reputation: 3054

Use redirect:

redirect 301 /ratings /ratings.php

Upvotes: -2

Related Questions