Welcome to WebmasterWorld Guest from 54.146.239.96

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewite after forum move

     

orgaseo

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

10+ Year Member



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 :(

dcrombie

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]

orgaseo

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

10+ Year Member



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

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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]

Jim

orgaseo

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

10+ Year Member



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?

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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]

Jim

orgaseo

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

10+ Year Member



Yes, thanks a lot!

It is working now!

orgaseo

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

10+ Year Member



...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!

jdMorgan

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month