Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite and Variable in URI

         

bunker0

9:22 pm on Dec 8, 2007 (gmt 0)

10+ Year Member



Hi All,

What Im tring to do is rewrite urls that have a folder that contains the word benidorm to "existing folders" without using RewriteMap because my hosting provaider doesnt allow it.

The problem is not with RewriteCond but with the actual RewriteRule, I have no idea how to rewrite /benidorm_restaurants/ to /benidorm-food/ or /deportes_benidorm/ to /benidorm-sport/ in a general way so that if I add a new folder, and therefor new content to the website, this rule would trigger and rewrite the URL.

All this is due to a languaje issue, I want both /benidorm_deportes/ and /benidorm_sport/ to rewrite to /benidorm-deportes/.

Any Idea?

My code in htaccess is ( so far... )

The First Two rules work Ok... its the Base Folders issue...

#Article
RewriteCond %{REQUEST_URI} /a/.*
#RewriteBase /article/.*
RewriteRule -([^/]+)-([^/]+)-([^/]+)-([^/]+)-([^/]+)\.html$ /include/article.php?port=$1&cat=$2&subcat=$3&id=$4&lang=$5 [QSA,L]

#Content
RewriteCond %{REQUEST_URI} /c/.*
#RewriteBase /content/.*
RewriteRule -([^/]+)-([^/]+)-([^/]+)-([^/]+)\.html$ /include/article.php?port=$1&cat=$2&subcat=$3&lang=$4 [QSA,L]

#base folders
RewriteCond %{REQUEST_URI}!/c/.* [OR]
RewriteCond %{REQUEST_URI}!/a/.* [OR]
RewriteCond %{REQUEST_URI} /*_benidorm/.* [OR]
RewriteCond %{REQUEST_URI} /benidorm_*/.*
RewriteRule (.*)\.html /index.php

Thx in advanced!

jdMorgan

9:57 pm on Dec 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code has several errors, and I can't tell what your URLs look like from examining it, so all I can do is answer your specific question:
All this is due to a language issue, I want both /benidorm_deportes/ and /benidorm_sport/ to rewrite to /benidorm-deportes/.


RewriteRule ^benidorm_(deportes¦sport)/$ /benidorm-deportes/ [L]

Replace the broken pipe "¦" character with a solid pipe character before use; Posting on this forum modifies the pipe characters.

In addition to the errors, it looks like the code you're using is far more complicated than it needs to be. However, it is difficult to determine how to improve it without knowing what your URL-set looks like.

Jim

bunker0

11:30 pm on Dec 8, 2007 (gmt 0)

10+ Year Member



HI Jim,

Basiclly my URLS look like this /c/benidorm_noche/bares_benidorm-1-103-1-es.html and /a/restaurantes_benidorm/restaurante_mamma_leone_benidorm-1-102-4-1-es.html

But I also have "base folders" that are called /benidorm-deporte/ for example, your example works Ok for the existing folders, but how could I create a rule to rewrite URLs automaticlly when a new folder is created in the structure of the web? Like /benidorm_whatever/ or /whatever_benidorm/?

Is this posible?

Thx again!

jdMorgan

12:49 am on Dec 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have no idea how to rewrite /benidorm_restaurants/ to /benidorm-food/ or /deportes_benidorm/ to /benidorm-sport/ in a general way so that if I add a new folder, and therefor new content to the website, this rule would trigger and rewrite the URL.

The problem is, that if you are changing "words" in the URL, then mod_rewrite has no way to associate the new word with the old word. So, you will end up with several rules if you want to change "restaurants" to "food" and to change "deportes" to "sport" -- Word changes must be handled on a one-at-a-time basis.

As for the "content" and the "article" rules, you'll probably need to make a complete list of all of the URL roots and all of the corresponding script paths that they need to be mapped to, and work from that.

This looks like a project that is really too big for a forum thread. All I can really suggest is that you change your existing rules like this to make them much more efficient:

#Content
RewriteRule ^c/.*-([^-]+)-([^-]+)-([^-]+)-([^.]+)\.html$ /include/article.php?port=$1&cat=$2&subcat=$3&lang=$4 [QSA,L]

Jim