Forum Moderators: phranque

Message Too Old, No Replies

rewriting htaccess

         

Fizzy

12:26 am on Jan 28, 2004 (gmt 0)

10+ Year Member



Hi all,

I'm very new to htaccess so please be gentle with me :)

I recently changed the format of my forum.
The old url looked like this :
[domain.tld...]

Now it looks like this
[domain.tld...]

I would like to use htaccess to change search engine results coming in to the old setup and have it automatically direct the visitor to the new url.

Is this something I can use htaccess to do?
If so, I would be very grateful if you could give me an example of what I would need to include.

Many thanks

Fizz

jdMorgan

5:08 am on Jan 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi fizz,

This recent thread [webmasterworld.com] may help you to focus-in on your problem more precisely.

The short answer is, "Yes, mod_rewrite can do that." - It's defining the "do that" part that is the initial problem.

If that thread helps you define your goal, then re-post back here.

Also, a good general introduction is also available in our Introduction to mod_rewrite [webmasterworld.com] tutorial -- Follow the links to the mod_rewrite documentation and the Regular-Expressions tutorial cired in the first post of that thread.

Jim

Fizzy

8:02 pm on Jan 29, 2004 (gmt 0)

10+ Year Member



Hi Jd,

Thanks for those links.
I've been trying to get my head around the info but it doesn't seem to be sticking.

The problem seems to be that the "909" part of the url is a dynamic so that would need to be numbers all the time but the numbers would change deoending on the thread number that the redirect had to go to.

I tried this

RewriteEngine On
RewriteRule ^http://www.domain\.tld/yabbse/index\.php\?thread=(.*)$ [domain.tld...] [L]

but that didn't work.

Do you have any suggestions where I might be going wrong?
Thanks

Fizz

jdMorgan

6:08 am on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the problem is that the query string is not available for testing in the RewriteRule pattern. You have to test it separately using RewriteCond.

You could use:


RewriteEngine On
RewriteCond %{QUERY_STRING} ^thread=([0-9]*)$
RewriteRule ^yabbse/index\.php$ http://www.example.com/yabbse/index.php/[b]t%1[/b].php [b][R=301,L][/b]

Or, with no validation to make sure the thread id is present and is actually a number:

RewriteEngine On
RewriteRule ^yabbse/index\.php$ http://www.example.com/yabbse/index.php/[b]t%{QUERY_STRING}[/b].php [b][R=301,L][/b]

You *may* need to add Options +FollowSymLinks ahead of RewriteEngine on if you get a server error when testing mod_rewrite code -- See your error log, it will tell you if this is so.

Jim

Fizzy

6:59 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



Hi Jim,

Wow! what an improvement Thank you :)

I used the option

RewriteCond %{QUERY_STRING} ^thread=([0-9]*)$
RewriteRule ^yabbse/index\.php$ [site.com...] [R=301,L]

The search engine results are now feeding in to the thread in the forum with one small glitch.
For some reason the Query_String seems to be repeating itself

The results appear like this

[site.com...]

The bit after the? seems to carry over from the query string but the url would normally look like this

[site.com...]

I tried dropping
RewriteCond %{QUERY_STRING} ^thread=([0-9]*)$
to
RewriteCond %{QUERY_STRING} ^([0-9]*)$
but that caused it to stop working,

It's nearly perfect, can you suggest where I can look to stop the doubling up?

Many thanks

Fizz

jdMorgan

7:52 pm on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fizz,

Doh! I always forget that part... :o

Adding a "?" to the end of the substitution will fix that.


RewriteCond %{QUERY_STRING} ^thread=([0-9]*)$
RewriteRule ^yabbse/index\.php$ http://www.site.com/yabbse/index.php/t%1.ph[b]p?[/b] [R=301,L]

The "?" will not show in the resulting URL - it just removes the pre-existing query string, so you don't get the "repeat" problem.

Jim

Fizzy

8:05 pm on Jan 30, 2004 (gmt 0)

10+ Year Member



Jim,

You are an absolute genius!

That? on the end did the trick perfectly, the urls are resolving a treat and I have you to thank for that.

If there was some sort of "reward" system here then you would certainly be at the top of the list. The help you gave was clear and concise enough for a newbie like me to follow easily and you took the time to explain what was going on. That makes all the difference to people like me.

Take a bow Jim. You deserve it.

Many thanks

Fizz