Forum Moderators: phranque

Message Too Old, No Replies

Rewrite URL with forwardslash problem

rewrite url problem

         

robincox

8:31 pm on Dec 7, 2009 (gmt 0)

10+ Year Member



Hi guys!

I am having an irritating problem with my URL rewrite in my .htacces file. I am trying to rewrite for example:

http://example.com/?sida=Fruit/Apples/Granny_Smith

to

Fruit/Apples/Granny_Smith

My .htaccess file looks as follows:
RewriteEngine On
RewriteRule ^([/a-zåäöA-ZÅÄÖ0-9_-]+)/?$ index.php?sida=$1 [L,QSA]

Here is my problem: if I for instance have a link like this
<a href="Fruit/Apples/Granny_Smith">Granny_Smith</a>
then it works fine the first time, the url says:

Fruit/Apples/Granny_Smith

But if I klick the link again the url now shows:

Fruit/Fruit/Apples/Granny_Smith

And if I click it again the url says:

Fruit/Fruit/Fruit/Apples/Granny_Smith

What am I doing wrong? Can somebody please write me a new .htacces that works, I would be ever so thankful.

[edited by: jdMorgan at 8:42 pm (utc) on Dec. 7, 2009]
[edit reason] example.com [/edit]

jdMorgan

8:43 pm on Dec 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As posted, your code is un-readable, due to non-standard characters in the regex patterns.

Also, your description is backwards, although not your rule: You are in fact rewriting a client request for the URLhttp://example.com/Fruit/Apples/Granny_Smith to the server filepath/index.php with a query string of "sida=Fruit/Apples/Granny_Smith".

The problem appears to be in the links on your pages or in your script. Make sure that the links on your pages for the URLs which are to be rewritten are in server-relative or canonical form. That is, use <a href="/Fruit/Apples/Granny_Smith"> or <a href="http://example.com/Fruit/Apples/Granny_Smith"> and not <a href="Fruit/Apples/Granny_Smith">

Jim

robincox

8:48 pm on Dec 7, 2009 (gmt 0)

10+ Year Member



It worked with: <a href="/Fruit/Apples/Granny_Smith">

Thanks alot, you made my day!