homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewite after forum move

 9:36 am on Nov 15, 2004 (gmt 0)

I had to move a forum to a subdomain but now some links from google just come up with 404. So I decided to do a mod_rewrite but can't get it to run.

My first test was the smiles image:

# Forum test
RewriteCond %{REQUEST_URI} ^/forum/images/smiles/*
RewriteRule hxxp://forum.foo.com/images/smiles/%1 [L]

That does not work. But a quick

RedirectMatch /forum/images/smiles/icon_smile.gif hxxp://forum.foo.com/images/smiles/icon_smile.gif

does the trick. But I can not write all 100 or so smiles into the .htaccess

And after that I think I miss something with that condition, which does not work.

I try to catch the URL: hxxp://www.foo.com/forum/viewforum.php?f=45&mark=topics&sid=811c43faa3330e3c8516a4607ee20616

RewriteCond %{REQUEST_URI} ^/forum/viewforum\.php?p=$
RewriteRule hxxp://forum.foo.com/viewforum\.php?p=%1 [L]

I really got lost here :(



 1:27 pm on Nov 15, 2004 (gmt 0)

You're missing some brackets. Should be something like:

# Forum test  
RewriteCond %{REQUEST_URI} ^/forum/images/smiles/(.*)
RewriteRule hxxp://forum.foo.com/images/smiles/%1 [R=301]


 2:06 pm on Nov 15, 2004 (gmt 0)

This is the entiry .htaccess but it does not work.

Maybe I miss an option or something:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/forum/images/smiles/(.*)
RewriteRule [forum.foo.com...] [R=301]
ErrorDocument 404 /error.php


 4:19 pm on Nov 15, 2004 (gmt 0)

This is simply a syntax error, and should have produced an error message in your server error log that stated that.

Try this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^forum/images/smiles/(.*)$ http://forum.foo.com/images/smiles/%1 [R=301,L]



 4:51 pm on Nov 15, 2004 (gmt 0)

But this does not work either :(

Redirects to [forum.foo.com...]

The image file, or whatever is requested, is not 'transfered' to the var %1

Is there something like a realtime debug for mod_rewrite?


 5:19 pm on Nov 15, 2004 (gmt 0)

Sorry, missed that error. RewriteRule pattern back-references use "$1", not "%1".

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^forum/images/smiles/(.*)$ http://forum.foo.com/images/smiles[b]/$1[/b] [R=301,L]



 5:27 pm on Nov 15, 2004 (gmt 0)

Yes, thanks a lot!

It is working now!


 5:36 pm on Nov 15, 2004 (gmt 0)

...but testing with

RewriteRule ^forum/viewtopic.php?p=([0-9]*)$ [forum.foo.bar...] [R=301,L]

does not work :(

<-- todo finaly understand mod_rewrite and read a book about it over x-mas!


 7:11 pm on Nov 15, 2004 (gmt 0)

Query strings are not considered to be part of a URL; They are data attached to a URL and will be forwarded to the resource at the given URL. For this reason, neither RewriteRule, nor RewriteCond %{REQUEST_URI} can "see" the query string attached to the requested URL.

You'll need to handle the query string separately in this case:

RewriteCond %{QUERY_STRING} ^p=([0-9]*)$
RewriteRule ^forum/viewtopic\.php$ http://forum.foo.bar/viewtopic.php?p=%1 [R=301,L]

The %1 will copy the query parameter matched by the RewriteCond into the RewriteRule's substitution URI.

There are several online resources about mod_rewrite and regular expressions cited in our forum charter, if you don't already have a book for the holidays. Take a quick look at the mod_rewrite documentation, and review the variables that the RewriteCond directive can examine.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved