| Author |
|
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 15 December 2009 at 3:19pm | IP Logged
|
|
|
Hi,
I have a question about rewritting an url.
I want to rewrite: www.domain.com/index.cfm?navigation_id=2&seo_url1=banden to www.domain.com/banden
then on the second level I have: www.domain.com/index.cfm?navigation_id=4&main_id=2&seo_url1=banden&seo_url2=contact to www.domain.com/banden/contact
Is that possible?
Thanks for any help.
Regards,
Samall
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 2:19am | IP Logged
|
|
|
Hi,
I think this is what you need:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^navigation_id=2&seo_url1=(.*) [NC]
RewriteRule ^index.cfm$ $1 [NC,L]
RewriteCond %{QUERY_STRING} ^navigation_id=4&main_id=2&seo_url1=(.*)&seo_url2=(.*) [NC]
RewriteRule ^index.cfm$ $1/$2 [NC,L]
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 3:26am | IP Logged
|
|
|
Hi Andrushka,
Thanks for your reply.
I'm not sure why but the rule is not working. When I try www.domain.com/banden I get a 404 file not found. I also was wondering if it was possible to make the navigation_id dynamic. Can I use instead of navigation_id=2 > navigation_id=(.*)?
My .htaccess file looks like this: # Helicon ISAPI_Rewrite configuration file # Version 3.1.0.68
RewriteEngine on RewriteBase / RewriteCond %{QUERY_STRING} ^navigation_id=2&seo_url1=(.*) [NC] RewriteRule ^index.cfm$ $1 [NC,L] RewriteCond %{QUERY_STRING} ^navigation_id=4&main_id=2&seo_url1=(.*)&seo_url2=(.*) [NC] RewriteRule ^index.cfm$ $1/$2 [NC,L]
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 3:53am | IP Logged
|
|
|
Hi,
well, yes. I did only one way rewrite
from
www.domain.com/index.cfm?navigation_id=2&seo_url1=banden
to
www.domain.com/banden
and nothing was said about redirect www.domain.com/banden to www.domain.com/index.cfm?navigation_id=2&seo_url1=banden.
Just add:
RewriteRule ^banden$ www.domain.com/index.cfm?navigation_id=2&seo_url1=banden [NC,R=301,L]
And sure you can make your id dynamic. and if there're going to be many id's i'd suggest using mapfiles. as it's
discribed in FAQ
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 4:06am | IP Logged
|
|
|
Hi, thanks again.
I don't want to redirect. I want to rewrite: index.cfm?navigation_id=2&seo_url1=banden to /banden
so when I type domain.com/banden I will see the page.
Thanks
Edited by samall2 - 16 December 2009 at 4:08am
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 4:30am | IP Logged
|
|
|
Here is what you need:
RewriteEngine on
RewriteBase /
RewriteRule ^banden$ index.cfm?navigation_id=2&seo_url1=banden [NC,L]
RewriteRule ^banden/contact$ index.cfm?navigation_id=4&main_id=2&seo_url1=banden&seo_url2=contact [NC,L]
ps. i'd suggest using mapfiles if more that 100-200 rules like this one needed.
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 4:34am | IP Logged
|
|
|
Oke thanks that is working.
So it is not posible to take the variable seo_url1=..... and use that word for the rewrite rule?
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 5:08am | IP Logged
|
|
|
Aha, you'll need map file:
Create a map file in the same folder with .htaccess file that you use. And fill it this way:
banden navigation_id=2&seo_url1=banden
banden/contact navigation_id=4&main_id=2&seo_url1=banden&seo_url2=contact
etc navigation_id=5&main_id=5&seo_url5=banden&seo_url5=contact
etc
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt [NC]
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)$ index.cfm?${mapfile:$1} [NC,L]
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 5:17am | IP Logged
|
|
|
Thanks again for your reply.
I'm just wondering if it is really necessary to create a map file. I have used Isapi 2 and there this was working fine:
RewriteRule /content/([^/]+) /content.cfm\?url_name=$1 [I,L] (result was www.domain.com/content/banden)
and
RewriteRule /content/([^/]+)/([^/]+) /content.cfm\?url_name=$1&action=$2 [I,L]
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 5:43am | IP Logged
|
|
|
Mapfile makes it easier to execute huge amount of rules. So it is recommended.
But you can continue working without it.
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 5:46am | IP Logged
|
|
|
Yeah but you are missing the point, or I'm missing it (-: I want it to be very dynamic. So I don't know what page a user creates. When a user adds a new page I have to add it in the map file manual, and I don't want to do that.
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 6:45am | IP Logged
|
|
|
It's always been a choice...
make it avoid slow work of ISAPI_Rewrite, but add pages manually,
OR
avoid writing URLs to the map files, but have some issues when amount of rules will exceed hundreds.
p.s. You may resolve this problem using any CMS with ISAPI_Rewrite
Edited by AndrushkaUS - 16 December 2009 at 6:46am
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 16 December 2009 at 8:26am | IP Logged
|
|
|
But isn't that the advantage of a dynamic rule? A dynamic rule needs only one line which rewrite all url's.
btw the mapfile is also working. Thanks for that.
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 16 December 2009 at 8:35am | IP Logged
|
|
|
I'd suggest separating:
index.cfm?navigation_id=(.*)&main_id=(.*)&seo_url1=(.*)&seo_url2=(.*)
any criterias that are changing put into mapfile and have all your rules rewriten.
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 17 December 2009 at 10:29am | IP Logged
|
|
|
Still one more question.
I have create a map file: test navigation_id=2
So my url is working www.domain.com/test Now on that page I can not use my variable navigation_id, which is in this case 2. Is there a way I can use it?
Regards
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 18 December 2009 at 3:22am | IP Logged
|
|
|
So you want navigation_id=2 to be shown in adress bar?
just add [R] flag at the end of the rule, so that it would be [NC,R,L]
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 18 December 2009 at 3:28am | IP Logged
|
|
|
No I don't want to see it in my url, I want to use in my query.
let say I have an index.cfm page:
<cfquery datasource...> select something from table where id = #url.navigation_id# </cfquery>
Now this is working fine with RewriteRule ^banden$ index.cfm?navigation_id=2&seo_url1=banden [NC,L]
But now I use the map file, and I receive the message that url.navigation_id can not be found.
Please see: http://test.digitalmedialab.nl/samiech which is the same as http://test.digitalmedialab.nl/index.cfm?navigation_id=2&seo_url1=samiech
So what I want is to use the navigation_id variable which is coming out of my mapfile.txt
Hope you understand the question, because it is hard to explain.
Thanks again
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 18 December 2009 at 3:45am | IP Logged
|
|
|
Lets make a test:
Insert in your mapfile this entry:
samiech 2
As for test try to run this rule:
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt [NC]
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)$ index.cfm?navigation_id=${mapfile:$1}&seo_url1=$1 [NC,L]
|
| Back to Top |
|
| |
samall2 Newbie

Joined: 15 December 2009
Online Status: Offline Posts: 38
|
| Posted: 18 December 2009 at 3:59am | IP Logged
|
|
|
Yes that is working! Thanks!
Now for the level 2 navigation, I have: http://test.digitalmedialab.nl/index.cfm?navigation_id=4&main_id=2&seo_url1=samiech&seo_url2=test
I want to to be: http://test.digi...nl/samiech/test
|
| Back to Top |
|
| |
Guests Guest

Joined: 01 October 2003
Online Status: Online Posts: -111
|
| Posted: 18 December 2009 at 4:17am | IP Logged
|
|
|
Lets make another test:
Create another mapfile. Lets say it's mapf.txt:
test 2
Add for test this rule:
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:mapfile.txt [NC]
RewriteMap mapf txt:mapf.txt [NC]
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^([^/]+)/([^/]+)$ index.cfm?navigation_id=${mapfile:$1}&main_id=${mapfile:$2}&seo_url1=$1&seo_url2=$2 [NC,L]
This must work
|
| Back to Top |
|
| |