Redirecting ugly URLs to pretty URLs? - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-24-2009, 11:48 PM   #1 (permalink)
Junior Member
 
Join Date: Dec 2008
Posts: 27
Default Redirecting ugly URLs to pretty URLs?

Hi -

I'm not sure if this goes in the PHP section, so if someone knows where I should post this, please feel free to tell me.

I am trying to change my 'ugly' URLs into 'pretty' URLs. To do this I am using .htaccess and mod_rewrite.

What I want to accomplish is change all of my links that look like this:

Code:
http://www.domain.com/file.php?act=get&id=542
to something like this:

Code:
http://www.domain.com/file/get/542.html
That part is easy as I use a Rewrite rule like this:

Code:
RewriteRule ^([a-z0-9]+)/[get]+/([0-9]+)\.html $1.php?act=get&id=$2 [L,NC]
However, since my site is indexed I am concerned about both the pretty and ugly URLs working. I'd like to redirect the ugly URLs to the pretty URLs. This is turning out to be fairly difficult.

I think I need to do something like this:

Code:
RewriteCond %{QUERY_STRING} ^act=get&id=([0-9]+)$
RewriteRule ^/([a-z0-9]+).php$ http://www.domain.com/test/$1/get/$2.htm? [L,R=301]
note that I am doing this in a 'test' folder in my public_html folder. The .htaccess file is in the test folder, so that should not be an issue, correct? Could using a RewriteRule to turn the ugly URL into a pretty URL and then another RewriteRule to change the ugly one into the pretty one cause problems? This does seem somewhat circular... Does the order of the RewriteRules matter? Should one rewrite rule appear before the other in the .htaccess file?

what am i doing wrong with my rewrite rule? any suggestions on getting the ugly url to redirect to the pretty url?

Thanks!

Last edited by zenthoef; 01-24-2009 at 11:51 PM.
zenthoef is offline   Reply With Quote
Sponsored Links
Old 01-27-2009, 01:25 AM   #2 (permalink)
Regular User
 
Join Date: Feb 2008
Location: Florida
Posts: 480
Default Re: Redirecting ugly URLs to pretty URLs?

not what the problem but this might help: 301 Redirect - How to create Redirects
__________________
Dog Shock Collars
bogs is offline   Reply With Quote
Old 02-10-2009, 04:11 AM   #3 (permalink)
Junior Member
 
BlueBoden's Avatar
 
Join Date: Feb 2009
Posts: 53
Default Re: Redirecting ugly URLs to pretty URLs?

Have a look at Redirecting pages with htaccess
BlueBoden is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 07:34 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting