Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Website and Server Administration Forum


You are currently viewing our Website and Server Administration Forum as a guest. Please register to participate.
Login



Reply
Please help! Mod_rewrite is toooo hard!
Old 05-27-2008, 11:05 PM Please help! Mod_rewrite is toooo hard!
Novice Talker

Posts: 7
Trades: 0
Hi all, I run a restaurant review site for one city, and am in the process of rewriting some of the code so that I can add new cities easily with no new code

neccesary each time I add one. I also really want to keep the SEO rankings I'm getting. I'm finding mod_rewrite really tricky to work out, so was hoping

someone would be so kind as to help me out?

I need a .htaccess file to do the following:


Rewrite all URLs for city and preserve any querystrings, e.g.

mydomain.com/london/index.php
mydomain.com/london/search.php?type=new
mydomain.com/london/10.php

rewritten to

mydomain.com/index.html?city=london
mydomain.com/search.html?city=london&type=new
mydomain.com/restaurant.php?city=london&rid=10

Basically all address in folder thecity written to root page.php?city=thecity, but css and image/flash links need to stay relative to the root.

Even better, would I be able to have something such as the restaurant's name instead of an ID number? Would this help with SEO rankings?



Here is my current .htaccess file that a friend wrote for me when I launched 3 years ago. The rules for the search.php page need to be kept intact but taking

into account the new city folder structure.

Code:
RewriteEngine on
RewriteBase /
RewriteRule ^brighton.html$ /search.php
RewriteRule ^viewall.html$ /search.php?orderby=name
RewriteRule ^toprated.html$ /search.php?top=true
RewriteRule ^new.html$ /search.php?new=true
RewriteRule ^mostreviewed.html$ /search.php?most=true
RewriteRule ^([A-Za-z0-9-]+).html?$ /restaurant.php?rid=$1
RewriteCond %{HTTP_HOST} !^(.*)\.mydomain\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
Am I being an idiot? Is it something really simple that I should be able to work out or am I trying to do something the wrong way? Mod_rewrite is obviously a ver powerful tool, and I would love to be able to make full use of it. I wasn't sure if it was a good idea or etiquette to add my site's address to this post but I can if it will help (edit: whoops, just realised it's in my sig any way!).

I would really really appreciate some help with this as even though PHP is not a problem for me, mod_rewrite is becoming a real pain! Every time I think I've fixed something I seem to break another thing!
__________________

Please login or register to view this content. Registration is FREE

Last edited by markmc; 05-27-2008 at 11:22 PM..
markmc is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-27-2008, 11:58 PM Re: Please help! Mod_rewrite is toooo hard!
Novice Talker

Posts: 7
Trades: 0
OK so I have something that pretty much works:

Code:
RewriteEngine on RewriteBase / RewriteRule ^mcfarlane/.*$ - [PT]

#Rewrite all searches
RewriteRule ^brighton.html$ ^/search.php
RewriteRule ^viewall.html$ ^/search.php?orderby=name
RewriteRule ^toprated.html$ ^/search.php?top=true
RewriteRule ^new.html$ ^/search.php?new=true
RewriteRule ^mostreviewed.html$ ^/search.php?most=true
RewriteRule ^([A-Za-z0-9-]+).html?$ ^/restaurant.php?rid=$1

#Rewrite style.css
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+).css?$ /style.css

#Rewrite images
RewriteRule ^([A-Za-z0-9-]+)/images/([A-Za-z0-9-_]+).gif?$ /images/$2.gif
RewriteRule ^([A-Za-z0-9-]+)/images/([A-Za-z0-9-_]+).jpg?$ /images/$2.jpg
RewriteRule ^([A-Za-z0-9-]+)/images/([A-Za-z0-9-_]+).bmp?$ /images/$2.bmp
RewriteRule ^([A-Za-z0-9-]+)/images/([A-Za-z0-9-_]+).swf?$ /images/$2.swf

#Rewrite searches from /city/search.php to /search.php?city=city
RewriteRule ^([A-Za-z0-9-]+)/search.php$ /search.php?city=$1


RewriteRule ^([A-Za-z0-9-]+)$ /$1/ [R]
RewriteRule ^([A-Za-z0-9-]+)/$ /index.php?city=$1

#For restaurant listing
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ /$2?&city=$1
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+).php$ /$2.php?&city=$1

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+).html$ /restaurant.php?rid=$2&city=$1

RewriteCond %{HTTP_HOST} !^(.*)\.menureview\.co.uk$ [NC]
#RewriteRule ^(.*)$ http://www.menureview.co.uk/$1 [R=301,L]
Could this be better written?
__________________

Please login or register to view this content. Registration is FREE
markmc is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Please help! Mod_rewrite is toooo hard!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20872 seconds with 12 queries