.htaccess - Old site URLs to New site

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

.htaccess - Old site URLs to New site

Post by psurrena »

I converted an old site to use the codeigniter framework and have a question about routing the old urls to the new.

I am using the standard rewrite to get rid of the index.php and towards the end I’m trying to achieve what I’m talking about above. It does not seem to work, any ideas?

Code: Select all

DirectoryIndex index.php
 
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|pdf|swf|xml|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
 
RewriteRule ^project-(.*)-(.*).html$ projects/detail/$1/$2
project-(.*)-(.*).html is the old URL format
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: .htaccess - Old site URLs to New site

Post by ridgerunner »

Try reversing the order of the two rules. And your second rule needs to add some query string goodness before it will work. Try something along the lines of:

Code: Select all

RewriteEngine on
RewriteRule ^project-([^/\-]+)-([^/\-]+).html$ projects/detail/$1/$2
 
RewriteCond $1 !^(index\.php|images|css|js|pdf|swf|xml|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?urlvariable=$1 [L]
Also changed the dot-star to a more precise expression.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: .htaccess - Old site URLs to New site

Post by psurrena »

Thanks!

One note, if anyone is using the codeigniter framework + hostmonster, the URI Protocol should be set as:
$config['uri_protocol'] = "ORIG_PATH_INFO";
Post Reply