Forum Moderators: phranque

Message Too Old, No Replies

Problems with "catch all" in rewrite

Concatenation problems with a rewrite rule. Ex (site.com/items/items/item2)

         

PatomaS

3:22 pm on Feb 10, 2008 (gmt 0)

10+ Year Member



Hi people

I'm quite noob using rewrite and i have a problematic rule right now.

This is the structure of the site i'm working on:

  • /
  • /index.php
  • /kernel (all the functions)
  • /img (images)
  • /themes (aesthetic of the site, css and js)
  • /themes/basic
  • /themes/...
  • /languages (different languages for the site)
  • /languages/en
  • /languages/es
  • /languages/...

I am using rewrite to catch all links, redirect them to the index.php and show the content that is stored in the languages folders.

So for instance, assuming the site is called site.com (quite original isn't?) and the active language is en
a link in the main page pointing to items/item1, will be presented by the /index.php with the content of /languages/en/items/item1.

So the real structure is inside the languages.

The rewrite rule i'm using is:
RewriteRule!\.(gif¦jpg¦png¦css¦)$ index.php

So far, everything is working properly, but now imagine this situation:
you are in: site.com/items/item1, and in that page, you have a list of all the items, then you click on item2, the new URL becomes site.com/items/items/item2 and so on if you keep clicking items of the list.

The site still works properly, all the links point to the right places, all the images are present, etc, but the URL is obviously wrong.

I have been trying different rules, but i can not make it work, can any one help me here, or point me in the right direction.

Thank you for your time and excuse me for the long explanation.

:)

Bye

jdMorgan

7:33 pm on Feb 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fairly difficult to discuss this without seeing an example of the link to /item2...

Jim

PatomaS

2:26 am on Feb 11, 2008 (gmt 0)

10+ Year Member



Hi

True, excuse me for that.

This is how those links look:
<a href="items/item1">Item 1</a>
<a href="items/item2">Item 2</a>
<a href="items/item3">Item 3</a>

Bye

jdMorgan

3:20 am on Feb 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to use server-relative links, then:

<a href="/items/item1">Item 1</a>
<a href="/items/item2">Item 2</a>
<a href="/items/item3">Item 3</a>

Remember, it is the browser that resolves relative links. If the browser thinks you're on a page in the /items subdirectory, and you link from that page to "items/item1" then the browser will request /items/items/item1 as you describe. Using a server-relative link causes the browser to ignore the current subdirectory, and append the URL-path to the current domain only.

Jim

PatomaS

5:42 am on Feb 11, 2008 (gmt 0)

10+ Year Member



Hi

You are absolutely right, and i forgot that basic and important part.

The problem is completely solved.

Thanks.

Bye