Ultrashock Forums > Development > Server Side
.htaccess rewrite url script help

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
.htaccess rewrite url script help
Old 2009-01-04

I have the following .htaccess file below.

# permanently redirect specific IP request for entire site
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} 12\.28\.84
RewriteRule \.*$ http://www.buildlastingsuccess.com/ [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/cpanel/.*
RewriteCond %{HTTP_HOST} ^www\.timefreedomnow\.net [OR]
RewriteCond %{HTTP_HOST} ^timefreedomnow\.net
RewriteRule ^(.*)$ /gcp/$1 [L,QSA]

I want to add a rule to take any request coming in from the address like this:
http://www.timefreedomnow.net/?username
I want them to redirect to:
http://www.timefreedomnow.net/profile/username
Where it appends the username from the first url to the end of the second url.

Thanks everyone,

Sean McGilvray
postbit arrow 2 comments | 784 views postbit arrow Reply: with Quote   
Registered User
smcgilvray is offline
seperator
Posts: 3
2009-01-04
smcgilvray lives in United States
seperator

Ultrashock Member Comments:
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2009-01-04 #2 Old  
Welcome to Ultrashock, Sean

This should work I think...

Code:
RewriteEngine On

RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^([a-z0-9]+)$ [NC]
RewriteRule .* /profile/%1? [L,R=301]
1. Make sure the request is pointing at the root directory.
2. Make sure the query string has one or more characters and limit those characters to ones allowed in the username.
3. Redirect.

Notice the single ? at the end of the redirect URI, that is required to remove the original query string from the URI, without it the original query string will be sent over to the page you are redirecting to.

FYI: You only need one 'RewriteEngine On' line in the htaccess file.

Reply With Quote  
smcgilvray smcgilvray is offline smcgilvray lives in United States 2009-01-04 #3 Old  
You are the man. That worked perfectly.

Thank you,

Sean McGilvray
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: