301 mapfile help needed
6 posts
• Page 1 of 1
301 mapfile help needed
Trying to get my head around this and searched for ages to find solution, i'm sure its not this difficult
Basically i have a simple mapfile, example:
All i want to happen is that the rewrite rule looks up the mapfile and does a 301 redirect.
Also, the domain could contain www so the rule should still apply.
In fact the domain.com won't change.
I've tried the following to no avail, making sure http://domain.com is removed so it matches the xxx/yyyy:
This didn't seem to do anything.
then I tried this, keeping the domain.com part in the map file:
This got stuck in a loop and didn't work.
Can anyone help.
much appreciated
Basically i have a simple mapfile, example:
- Code: Select all
domain.com/xxxx/yyyy /shop.asp/somewhere/12345
domain.com/xxxx/zzzz /shop.asp/somewhere/12345678
domain.com/zzzz /shop.asp/somewhere2/12345678
All i want to happen is that the rewrite rule looks up the mapfile and does a 301 redirect.
Also, the domain could contain www so the rule should still apply.
In fact the domain.com won't change.
I've tried the following to no avail, making sure http://domain.com is removed so it matches the xxx/yyyy:
- Code: Select all
RewriteMap mapfile txt:d:\xyz\map.txt
RewriteRule .*domain.com/(.*) http://www.domain.com/${mapfile:$1} [L,R=301]
This didn't seem to do anything.
then I tried this, keeping the domain.com part in the map file:
- Code: Select all
RewriteMap mapfile txt:d:\xyz\map.txt
RewriteRule /(.*) http://www.domain.com/${mapfile:$1} [R=301,L]
This got stuck in a loop and didn't work.
Can anyone help.
much appreciated
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: 301 mapfile help needed
You got really close to the problem.
All you need is a condition that checks if the request matches the mapfile:
Regards
Andrew
All you need is a condition that checks if the request matches the mapfile:
- Code: Select all
RewriteEngine on
RewriteBase /
RewriteMap mapfile txt:d:\xyz\map.txt
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule (.*) http://www.domain.com/${mapfile:$1} [NC,R=301,L]
Regards
Andrew
Re: 301 mapfile help needed
Many thanks for the reply.
How silly of me..... it was late (midnight) and totally missed the condition needed.
All working now
How silly of me..... it was late (midnight) and totally missed the condition needed.
All working now
Re: 301 mapfile help needed
Hi
One other question if you can help.
I have another mapfile which is similar to the previous one, the difference is that the second parameter is a domain name.
so for example if the incoming request is
I need it to redirect to:
without the query string... just to the root
One other question if you can help.
I have another mapfile which is similar to the previous one, the difference is that the second parameter is a domain name.
so for example if the incoming request is
- Code: Select all
www.domain1.com/xyz/zzz
I need it to redirect to:
- Code: Select all
www.domain2.com
without the query string... just to the root
- HeliconAndrew
- Posts: 1264
- Joined: 07 Mar 2012, 10:16
Re: 301 mapfile help needed
hello,
the rule would look like(i made it strictly for two-level URLs, as you described):
and in your mapfile you'll have entries as in the following:
Regards
Andrew
the rule would look like(i made it strictly for two-level URLs, as you described):
- Code: Select all
RewriteCond ${mapfile:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ([^/]+/[^/]+) http://${mapfile:$1}? [NC,R=301,L]
and in your mapfile you'll have entries as in the following:
- Code: Select all
aaa/bbbb www.domain2.com
ccc/ddd www.otherdomain.com
Regards
Andrew
Re: 301 mapfile help needed
Thanks again for the info.
I managed to find solution by trial and error
It seems I had forgotten to prepend with http://
I was getting the redirect added to the end of the initial url, but once i added in the http:// all worked fine.
thanks for your help its much appreciated.
I managed to find solution by trial and error
It seems I had forgotten to prepend with http://
I was getting the redirect added to the end of the initial url, but once i added in the http:// all worked fine.
thanks for your help its much appreciated.
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 7 guests