Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Trying to Rewrite URLs with Query Strings |
|
Author |
|
culpetm
Joined: 23 Feb 2013 Posts: 2 Location: Monterey, CA
|
Posted: Sat 23 Feb '13 20:05 Post subject: Trying to Rewrite URLs with Query Strings |
|
|
Hi everyone. Total newbie here. Been doing html and php for a few years. Just now venturing into Apache.
Anyway, I need help with the htaccess file for one of my sites. I've searched everywhere, and I can't find a solution for my problem.
System Info:
Easy Apache v3.18.1
CentOS 6.3 (x86_64)
So I'm trying to redirect all URLs in a certain query range to a new website.
ie
mydomain.com/?p=35000
mydomain.com/?p=35001
mydomain.com/?p=35002
mydomain.com/?p=35003
etc.
all need to 301 redirect to myotherdomain.com
I don't need to append each query to the new domain. All the URLs simply need to redirect to the naked domain of the other site.
so
mydomain.com/?p=35000 is not redirecting to myotherdomain.com/?p=35000
It is simply redirecting to myotherdomain.com
Also, I need to redirect the specific series ([35000-35999]) to the new domain.
Oh, and I want to redirect the www and the non-www URLs.
I've attempted to write the code myself, but when I upload the htaccess file, the URLs are not redirecting. I'm doing something wrong.
Here's what I've tried:
Code: |
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteCond %{QUERY_STRING} ^p=([35000-35999]*)$
RewriteRule ^(.*)$ "http\:\/\/myotherdomain\.com\/" [R=301,L]
|
What did I mess up?
Thanks.
-Tim |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 26 Feb '13 12:50 Post subject: |
|
|
I think
this
Code: |
RewriteCond %{QUERY_STRING} ^p=([35000-35999]*)$
|
should be
Code: |
RewriteCond %{QUERY_STRING} ^p=([35000-35999]+)$
|
|
|
Back to top |
|
culpetm
Joined: 23 Feb 2013 Posts: 2 Location: Monterey, CA
|
Posted: Tue 26 Feb '13 17:35 Post subject: |
|
|
Thanks so much for the idea. I tried it, but it doesn't work.
By the way, a few minutes ago, I tried a regular redirect in order to make sure that my apache is working properly and to make sure that the htaccess file is in the right place.
I did this:
Code: |
RewriteEngine on
RewriteCond %{HTTP_HOST} ^slangbuzz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.slangbuzz\.com$
RewriteRule ^randomtext$ "http\:\/\/myotherdomain\.com\/" [R=301,L] |
And that simple redirect works fine.
I just can't figure our what's wrong with my query string redirect. |
|
Back to top |
|
|
|
|
|
|