apache mod rewrite question

  • fourthring
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152
  • Loc: San Diego / Beijing

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • fourthring
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152
  • Loc: San Diego / Beijing

Post 3+ Months Ago

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
  • Posts: 17

Post 3+ Months Ago

Thanks for sharing the solution!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: Communicationcrafts and 7 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.