apache mod rewrite question

  • fourthring
  • Graduate
  • Graduate
  • User avatar
  • Joined: Oct 28, 2004
  • Posts: 152
  • Loc: San Diego / Beijing
  • Status: Offline

Post April 1st, 2005, 10:06 am

HI I got a blog that I am trying to rewrite search engine friendly urls.

I have 3 different parameters for a script:

http://www.plateoftheday.com/index.php?p=
http://www.plateoftheday.com/index.php?m=
http://www.plateoftheday.com/index.php?cat=

I've written rules so it recognizes the url:
http://www.plateoftheday.com/m/20050317/ as index.php?m=20050317

Just trying to figure out how to flatten the files according to parameter variables.

i.e.
http://www.plateoftheday.com/index.php?p=1234 => http://www.plateoftheday.com/p/1234

http://www.plateoftheday.com/index.php?m=1234 => http://www.plateoftheday.com/m/1234

http://www.plateoftheday.com/index.php?cat=1234 => http://www.plateoftheday.com/cat/1234

Here's what I have so far in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
#RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule ^m/([0-9]+) /index.php?m=$1 [L]
RewriteRule ^p/([0-9]+) /index.php?p=$1 [L]
RewriteRule ^cat/([0-9]+) /index.php?cat=$1 [L]

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 1st, 2005, 10:06 am

  • fourthring
  • Graduate
  • Graduate
  • User avatar
  • Joined: Oct 28, 2004
  • Posts: 152
  • Loc: San Diego / Beijing
  • Status: Offline

Post April 4th, 2005, 1:00 pm

Got it from JD Morgan over at the Webmasterworld forum:

Here's what I did in case anyone has the same problem. I'm using word press for the blog by the way so this can be applied to any other blog as well:

Options +FollowSymLinks
RewriteEngine on

#rewrite the m,p and cat fake folders - no more index.php script.
RewriteRule ^(m|cat)/([0-9]+)/?$ /index.php?$1=$2 [L]

#fake folders for m and cat parameters
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?(m|cat)=([0-9]+)\ HTTP/
RewriteRule ^index\.php$ http://www.mydomain.com/%1/%2/? [R=301,L]


#for posts just do the post id as the directory name. skip the /p/ dir
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?p=([0-9]+)\ HTTP/
RewriteRule ^index\.php$ http://www.mydomain.com/%1/? [R=301,L]


#default for a numbered directory is posting.
RewriteRule ^([0-9]+)$ /$1/ [R=301]
RewriteRule ^([0-9]+)/$ /index.php?p=$1 [L]
  • Thermit
  • Novice
  • Novice
  • User avatar
  • Joined: Mar 31, 2005
  • Posts: 17
  • Status: Offline

Post April 4th, 2005, 1:40 pm

Thanks for sharing the solution!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 22 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.