Htaccess Static Redirect for URL with question mark

Alles, was den Apache betrifft, kann hier besprochen werden.

Htaccess Static Redirect for URL with question mark

Postby teauser » 07. December 2010 18:26

Hello and thank you for your help,

I'm trying to redirect http://www.mysite.com/folder1/index.cfm?tab=news to the static page http://www.mysite.com/folder2

I tried:
- RedirectMatch 301 /folder1/index\.cfm\?tab=news /folder2

- redirect 301 /folder1/index\.cfm\?tab=news /folder2

- redirect 301 "/folder1/index.cfm?tab=news" /folder2

None of them worked for me. The problem is the ?
I tried to escape it but it did not work

Any help?

Thanks a lot! :)
teauser
 
Posts: 3
Joined: 07. December 2010 18:23

Re: Htaccess Static Redirect for URL with question mark

Postby Nobbie » 07. December 2010 21:01

Das geht so auch nicht, man kann keine Query-URLs umleiten, nur Ordner und Dateien.

Also beispielsweise das geht:

Code: Select all
Redirect 301 /folder1/index.cfm /folder2


Wenn Du in Abhängigekeit des Querystrings (?tab=news) weiterleiten willst, musst Du das entweder via mod_rewrite versuchen oder in einem PHP Script. Mit dem einfachen Redirect geht das nicht.
Nobbie
 
Posts: 8768
Joined: 09. March 2008 13:04

Re: Htaccess Static Redirect for URL with question mark

Postby teauser » 07. December 2010 21:06

Thanks Nobbie. I don't speak German so whatever you said, thank you very much for your help.

The problem is that your redirect is not going to work for my site because of the number of queries I have on the same page. For example:

1. http://www.mysite.com/folder1/index.cfm?tab=news to the static page http://www.mysite.com/folder2
2. http://www.mysite.com/folder1/index.cfm?tab=contact to the static page http://www.mysite.com/contact
3. http://www.mysite.com/folder1/index.cfm?tab=map to the static page http://www.mysite.com/map

If I use Redirect 301 /folder1/index.cfm /folder2, all redirects for /folder1/index.cfm will go to /folder2

Thank you again :)
teauser
 
Posts: 3
Joined: 07. December 2010 18:23

Re: Htaccess Static Redirect for URL with question mark

Postby Nobbie » 07. December 2010 22:14

teauser wrote:Thanks Nobbie. I don't speak German so whatever you said, thank you very much for your help.


Ah. So why do you post in the german part of this forum instead of the english part??

P.S.: Basically (what i wrote previously) you cannot solve your problem by a simple redirect, you have to use mod_rewrite instead (which is by far more sophisticated than a simple redirect).
Nobbie
 
Posts: 8768
Joined: 09. March 2008 13:04

Re: Htaccess Static Redirect for URL with question mark

Postby teauser » 07. December 2010 23:54

Hi Nobbie,

Thank you for your answer. I didn't realize I was writing the post on the German forum. Sorry about that. And thank you for your your answer. I did it as you suggested and in case someone needs some help this is what worked for me:

RewriteCond %{QUERY_STRING} tab=news
RewriteRule ^folder1/index.cfm$ http://www.mysite.com/folder2/? [R=301,L]

Hint: I had to put it RIGHT after the RewriteEngine On
teauser
 
Posts: 3
Joined: 07. December 2010 18:23


Return to Apache

Who is online

Users browsing this forum: No registered users and 4 guests