Forum Mod Rewrite

New to mod_rewrite? This is a good place to start.

Forum Mod Rewrite

Postby The Leader » Sun May 17, 2009 4:27 pm

I want to rewrite the urls in my php forum to be SEO friendly.

Currently they look like this

http://www.logisticforums.com/forum/...pic.php?t=9067

I would like it to look like this.

http://www.topictitle.logisticforums.com

So I want:
- the url put converted from dynamic to static
- the topic title replace the topic id
- the topic tile be put before the domain instead of after it.

I know I need a .htaccess file but got no idea about the code I need in it.


Please help!
The Leader
 
Posts: 3
Joined: Sun May 17, 2009 4:15 pm
Location: Melbourne, Australia

Postby richardk » Mon May 18, 2009 11:19 am

It's a lot more complicated than just mod_rewrite.

- the topic tile be put before the domain instead of after it.

Why?

You need DNS and the server configured to send the sub domains to the mod_rewrite (probably in a .htaccess file). FAQ: Virtual sub domains.

- the topic title replace the topic id

FAQ: How to change a numeric ID into a name/title.

Then you need to consider length of topic title, stripping invalid characters, duplicate topic titles and what is supposed to happen when someone visits topictitle.example.com/somethinghere.

I think you'd be better off going for /forum/topic/topic_id/topic_title/ or similar.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby The Leader » Mon May 18, 2009 4:28 pm

Thanks Richard, what if I kept it simple and just added the title before the id?
The Leader
 
Posts: 3
Joined: Sun May 17, 2009 4:15 pm
Location: Melbourne, Australia

Postby richardk » Tue May 19, 2009 3:56 pm

Please provide an example.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby The Leader » Tue May 19, 2009 8:58 pm

The Leader
 
Posts: 3
Joined: Sun May 17, 2009 4:15 pm
Location: Melbourne, Australia

Postby richardk » Wed May 20, 2009 8:38 am

In a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^topic/([0-9]+)/?$ /forum/...pic.php?t=$1 [QSA,L]

You will need to fix /forum/...pic.php.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 99 guests

cron