Forum Moderators: phranque
I am a total beginner just starting with apache and need some help as I have been asked to make the change below.
I want any request to a specific URL to go to another specific URL
e.g
[my.com...] to redirect to goto
[my.com...]
I have tried the redirect and the commented out rewrite rule and none work
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^http\:\/\/www\.my\.com\/ballgames\?action\=football_games$
#RewriteRule (.*) [my.com...]
RedirectMatch ^http\:\/\/www\.my\.com\/ballgames\?action\=football_games$ [my.com...]
RewriteCond %{REQUEST_METHOD} ^(TRACEŠTRACK)
RewriteRule .* - [F]
</IfModule>
But none of them seem to work. Your help greatly needed.
Cheers
Pankaj
My guess is what your are trying to do is not what you think you are trying to do...
I am guessing you want static looking URL's, but dynamic content. This happens the other way around EG Your LINK goes to a static page that does not exist, then Apache catches the request and serves the right content from your page that does exist.
If my guess is correct, you might have another look a around at some of the posts to get an idea of what is going on, and how mod_rewrite works. (I know there are some that explain how things work very well.)
Then when you have a good idea of the information you need, someone will help you through the process when you get stuck.
(If I am guessing wrong, please let me know.)
Justin
Welcome to WebmasterWorld!
In this line:
#RewriteCond %{HTTP_HOST} ^http\:\/\/www\.my\.com\/ballgames\?action\=football_games$
These will not be present in the {HTTP_HOST} variable, which will contain only
"www.my.com", "www.my.com:80", "my.com", or "my.com:80"
Your second rule has the same kind of problem.
In order to check the path and query string, you'll need to use another RewriteCond:
RewriteCond %{HTTP_HOST} ^(www\.)?my\.com\
RewriteCond %{QUERY_STRING} ^action=football_games$
RewriteRule ^/ballgames/?$ http://www.my.com/football [R=301,L]
However, as Justin pointed out, this redirect will only work if "/ballgames" is an actual page that exists on your server. Otherwise, you probably want to do something different: You will need to change your pages to link to "/ballgames" and then rewrite that URL to http://www\.my\.com/ballgames/?action=football_games when it is requested from your server. Mod_rewrite changes *requested* URLs, not *output* URLs. Mod_rewrite takes effect after a request is received by your server, but before any content-handlers are invoked.
The link on your page is the URL that the browser will request. Mod_rewrite will then receive that requested URL, and rewrite it to the form needed to call your script.
Jim
Thank you for the welcome. I have a feeling I am not explaining myself very well. But the information you have given me allows me find out more if you get my meaning. Need to read a lot more and then hopefully I can explain myslef better.
Thanks for the help and no doubt I will be on post in the future :-) for help
Punks