View previous topic :: View next topic |
Author |
Message |
dmolavi Apprentice


Joined: 24 Feb 2003 Posts: 153 Location: Washington Township, NJ
|
Posted: Tue Jul 15, 2003 5:33 pm Post subject: apache rewrite issues |
|
|
i'm migrating part of my PHPNuke site from one of my servers to a new server, with a different domain name. the database is being transferred, thus the story/article/forum IDs are remaining the same. how would i craft a rewrite rule that would redirect people to the new server only for a certain subset of the articles? there is an "sid" field in the URL that would have to be checked; if it matches any one of the articles which has been moved, the URL should be rewritten.
thanks in advance, dm |
|
Back to top |
|
 |
fcgreg Apprentice


Joined: 17 May 2003 Posts: 264 Location: California, USA
|
Posted: Tue Jul 15, 2003 6:24 pm Post subject: mod_alias |
|
|
It somewhat depends on if you want to redirect someone to the new site as opposed to actually rewriting the URL and processing on the same server. Since you mentioned the content was moved to a new server, I'll give you an example with mod_alias (which does redirection).
mod_alias contains a statement named "RedirectMatch" that comes in handy for such cases, and mod_redirect has less overhead than mod_rewrite. You can use a regular expression to match on the URL (actually, the PATH in the URL), then forward to a new URL accordingly. It looks like this:
Code: | RedirectMatch [redirect-type] {pattern-to-match} {new-URL} |
The new location can use variable substitution just like you can in PERL. For example:
Code: | RedirectMatch temp (.*)\.(gif|jpg|png)$ http://newsite.com/image-store/$1.$2 |
The above snippet would send a temporary redirect of all image requests to a different server, keeping the same directory structure within the "image-store" directory.
From what you describe in your post this type of option should work just fine. However, if you need more powerful rewriting ability you may need mod_rewrite. _________________ Greg T. |
|
Back to top |
|
 |
dmolavi Apprentice


Joined: 24 Feb 2003 Posts: 153 Location: Washington Township, NJ
|
Posted: Tue Jul 15, 2003 6:31 pm Post subject: |
|
|
Quote: | It somewhat depends on if you want to redirect someone to the new site as opposed to actually rewriting the URL and processing on the same server. |
i'm a bit unclear as to the differences between the two items you mentioned here. the content will be moved to the new server (which is a virtual server, running on the same machine). as an example, the original URL would be:
http://www.yankeesinthesouth.org/modules.php?name=News&file=article&sid=21
and the new URL would be:
http://www.nukedgallery.net/modules.php?name=News&file=article&sid=21
The only difference being the www- part. However, I have a set of about a dozen articles (indicated by the "sid" field in the URL) out of all the original articles that will be moved (for example, sid 1,3,4,5,6,34,2,45 will move, the rest will remain at the original location).
Will your method take care of that? if so, in what file/section of the file would the redirectmatch code be placed?
thanks for your help |
|
Back to top |
|
 |
dmolavi Apprentice


Joined: 24 Feb 2003 Posts: 153 Location: Washington Township, NJ
|
Posted: Tue Jul 15, 2003 7:17 pm Post subject: |
|
|
here is the code i put in the <IfModule mod_alias.c> section of commonapache.conf: Code: | RedirectMatch permanent ^http://www.yankeesinthesouth.org/(.*)\&sid=(8|10|12|13|14|17|18|19|
21)(.*)$ http://www.nukedgallery.net/$1.$2.$3 |
however, this doesn't work...any tips?
EDIT: Apparantly, anything after a "?" in a URL is part of the query string and mod_rewrite seems to be the only way to go. so i'm guessing i have to have a separate Rewrite entry for each URL that needs redirection? crap... |
|
Back to top |
|
 |
fcgreg Apprentice


Joined: 17 May 2003 Posts: 264 Location: California, USA
|
Posted: Wed Jul 16, 2003 4:39 am Post subject: You're correct |
|
|
To my knowledge, the mod_alias module only matches against the PATH portion of the URL -- this means the hostname doesn't count for the match expression and neither does the QUERY_STRING (everything after the question mark). Now, if you include the RedirectMatch directive inside your Apache configuration files (as opposed to an .htaccess file), it should seamlessly pass your QUERY_STRING through to the new URL. However, since in this case you want to actually match against items in the QUERY_STRING, you will need the mod_rewrite module.
Now, regarding how you put code into the "<IfModule mod_..." common block:
Do you mean in your main section of your Apache config? If so, this is undesireable -- at least for what you're trying to do. You would be much better off putting redirect clauses inside of your VirtualHost containers, since that is where they most specifically apply (although technically you can put most of these directives anywhere in the configuration if you want/need to).
Based on the above, the following directive should work in your case:
(inside the VirtualHost container for yankeesinthesouth.org)
Code: | RewriteEngine on
RewriteCond %{QUERY_STRING} .*sid=(8|10|12|13|14|17|18|19|21).* [NC]
RewriteRule ^/(.*) http://www.nukedgallery.net/$1 [R=permanent,QSA,L] |
The above directives test the QUERY_STRING for the conditions for redirect. If the condition passes then the RewriteRule will come into play. The rule does a permanent redirect ("R=..." flag), appends the old QUERY_STRING ("QSA" flag), and doesn't process any more rules ("L" flag).
That should do it, based on what you provided. Whew! _________________ Greg T. |
|
Back to top |
|
 |
dmolavi Apprentice


Joined: 24 Feb 2003 Posts: 153 Location: Washington Township, NJ
|
Posted: Wed Jul 16, 2003 12:42 pm Post subject: |
|
|
perfect thanks. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|