homepage Welcome to WebmasterWorld Guest from 54.227.40.166
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod Rewrite - Hopelessly Lost....
Need a pointer please...
Nick_W




msg:1503313
 8:53 pm on Sep 18, 2003 (gmt 0)

Ok,

Pulling my hair out here:

I'm trying to turn this:

www.site.com/viewtopic.php?t=44

Into somthing reasonable like:

www.site.com/viewtopic/44.html

I have this so far, but I'm almost embarrassed to post it ;)

rewriteEngine On
rewriteRule ~viewtopic\.php/$ /viewtopic.php?t=$1

The ~ is actually a carrot, but for some astonishing reason my keyboard refuses to print one!

If someone can put me on the right track I'm sure I can work it out, I'd appreciate a jump start though ;)

Many thanks

Nick

 

bcolflesh




msg:1503314
 9:00 pm on Sep 18, 2003 (gmt 0)

RewriteRule ^(.*)viewtopic/(.*).html /viewtopic.php?t=$2

Nick_W




msg:1503315
 9:02 pm on Sep 18, 2003 (gmt 0)

Ahhhh....

Why the $2?

And much thanks, very decent of you ;)

Nick

bcolflesh




msg:1503316
 9:05 pm on Sep 18, 2003 (gmt 0)

Why the $2?

The second variable is the one you want to match.

I had to make up for my phpBB mod posting!

Nick_W




msg:1503317
 9:09 pm on Sep 18, 2003 (gmt 0)

Hmmm... I fear I'm missing somthing?


RewriteEngine On
RewriteRule ^(.*)viewtopic/(.*).html /viewtopic.php?t=$2

When I click a topic, it just goes to the regular url. Did I miss somthing?

Nick

coopster




msg:1503318
 9:12 pm on Sep 18, 2003 (gmt 0)

Do you have the pattern and substitution mixed up?
<edit>NO, you don't.<edit>

[edited by: coopster at 9:14 pm (utc) on Sep. 18, 2003]

bcolflesh




msg:1503319
 9:12 pm on Sep 18, 2003 (gmt 0)

You need to change the physical URLs to the format:

www.site.com/viewtopic/x.html

where x=your number - try the link:

www.site.com/viewtopic/44.html

Nick_W




msg:1503320
 9:18 pm on Sep 18, 2003 (gmt 0)

BINGO!

The link works, heh! ---- Is there an easy way of changing those urls in phpBB? -- sounds painfull....

Nick

bcolflesh




msg:1503321
 9:22 pm on Sep 18, 2003 (gmt 0)

Should only take a few seconds with a text search and replace tool - check the code on one of the pages and see how they construct the links.

It's probably a worthwhile task to make a complete rewrite guide for phpBB, given all the users...

Nick_W




msg:1503322
 9:30 pm on Sep 18, 2003 (gmt 0)

Thanks, I'll get too it.

I suppose the main files are just viewforum.php and viewtopic.php right?

DId you bother with the '?start=x' urls aswell?

Nick

jdMorgan




msg:1503323
 10:38 pm on Sep 18, 2003 (gmt 0)

Since a rewrite guide project is being suggested, I'd like to note that since the $1 backreference is not used, and since the pattern starts with a wild card, this code

RewriteEngine On
RewriteRule ^(.*)viewtopic/(.*).html /viewtopic.php?t=$2

could just as well be shortened/simplified to

RewriteEngine On
RewriteRule viewtopic/(.*)\.html /viewtopic.php?t=$1 [L]

(Note also the escaped period in "\.html", and stick a [L] flag on there unless you have a reason not to do so.)

Jim

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