3

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.stack.imgur.com/y5hqA.gif

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

Help would be greatly appreciated!

Thanks everyone

gioele
  • 9,748
  • 5
  • 55
  • 80
Joel Murphy
  • 2,472
  • 3
  • 29
  • 47

4 Answers4

3

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
onatm
  • 816
  • 1
  • 11
  • 29
  • Problem solved, thanks :D Just wondering though, should I create another rule if there isnt a '/' after the url, e.g http://localhost/food/ratings/ and http://localhost/food/ratings ? as they don't both point to the same place :/ – Joel Murphy Oct 26 '11 at 13:46
1

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.

Moyshe
  • 1,122
  • 1
  • 11
  • 19
0

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.

Austin S.
  • 304
  • 1
  • 6
-2

Use redirect:

redirect 301 /ratings /ratings.php
jschorr
  • 3,034
  • 1
  • 17
  • 20