.htaccess rewrite

I am having trouble with my .htaccess:

For my affiliates to get credit, they need to send traffic to mydoman.com/affiliates/username
with "username" being a variable based on their selection at registration.  

I would like for them to be able to send traffic to mydomain/username instead.  

Here is where I am...this is my .htaccess before trying to do this:
	
<IfModule mod_rewrite.c>	

RewriteEngine On
	

RewriteCond %{HTTP_HOST} ^mydomain.com.(.*)
RewriteRule ^(.*)$ http://www.mydomain.com/$1  [R=301,L]
	#
	#  Full path to your site
	#
	RewriteBase /
	

	#
	#  Rules
	#
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*) index.php?do=/$1
	
	# Image Access Protection
	# RewriteRule ^file/pic/photo/(.*)\.(.*)$ static/image.php?file=$1&ext=$2
</IfModule>

# Modify Headers
<IfModule mod_headers.c>
	# Cache files
	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
		Header set Cache-Control "public"
		Header set Expires "Mon, 20 Apr 2015 20:00:00 GMT"
		Header unset Last-Modified
	</FilesMatch>
	 
	# Cache JavaScript & CSS
	<FilesMatch "\.(js|css)$">
		Header set Cache-Control "public"
		Header set Expires "Mon, 20 Apr 2015 20:00:00 GMT"
		Header unset Last-Modified
	</FilesMatch>
</IfModule>

# Compress JavaScript & CSS
<IfModule mod_deflate.c>
	<FilesMatch "\.(js|css)$">
		SetOutputFilter DEFLATE
	</FilesMatch>
</IfModule>

Open in new window


and this is what I was told would do the job, without affecting my current folders and files:
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteRule ^$ affiliates [L]

Open in new window


There are some similar things in my current htaccess and I was not sure if they conflict or not.  

Thanks!
Large_FarvaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jeremycrussellCommented:
If I understand your question (and information) correctly...  I think

RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]

Should  be

RewriteRule (.*) http://www.mydomain.com/affiliates/$1 [R=301,L]

0
Large_FarvaAuthor Commented:
Thanks for the help.  I changed line 8 in the first snippet to what you suggested...I have not added the second snippet to the file yet.

Just to be clear, I need www.mydomain.com/username 
with username being a variable ( and not an exisiting filename or folder)
to be sent to www.mydomain.com/affiliates/username

Thanks.
0
Large_FarvaAuthor Commented:
^^^it did not work.
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

jeremycrussellCommented:
You'll want this line

RewriteRule (.*) http://www.mydomain.com/affiliates/$1 [R=301,L]

To come directly *after* these...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

There may also be other conditions you'll need, but you can try this first.

Also, is

RewriteRule ^(.*) index.php?do=/$1

A required rule for something?

This is essentially rewriting http://mydomain.com/something to http://mydomain.com/index.php=/something , were you testing you do you need this to work as well?


0
Large_FarvaAuthor Commented:
Ok..getting close.

Here is what I have now:
RewriteEngine On
	
	RewriteBase /

	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule (.*) http://www.mydomain.com/affiliates/$1 [R=301,L]
	#RewriteRule ^(.*) index.php?do=/$1

Open in new window


I commented out the rule in question on your last post and it works better without it.
The way it is now it does redirect as needed for anything other than current files/folders but it adds an extra "/" in the url after the .com:  www.mydomain.com//affiliates/username

The main problem now is that it also redirects all my links in the social network software in root to the affiliates folder, which I image is the reason for the other commented out rule.  
Since it is a cms, it is not recognizing the links there as established files/folders.  

Thanks.
 
0
jeremycrussellCommented:
You can take out the "RewriteBase /" to fix the double slash.

Ok, Ya, that's what I was afraid was going to happen and why that rule was there.  So there are URIs that are associated with the CMS, that aren't actual directories/files under your document root, but are actions sent the the index.php of the CMS to be rendered.

Which do you have fewer of, links within the CMS, or affiliate users?  What is probably going to have to happen is that you'll have to setup RewriteCond for one of the other listing them out.  For example, if you went with your possible CMS URIs then you would end up with something like thist (I just made up some URIs that are the exception to the affiliate usernames).

RewriteCond %{REQUEST_URI} ^/images
RewriteCond %{REQUEST_URI} ^/contact
RewriteRule ^(.*) index.php?do=/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.mydomain.com/affiliates/$1 [R=301,L]
0
Large_FarvaAuthor Commented:
Well, here is another problem we may not be able to get around.  On one hand I am asking for  www.mydomain/username to go to the affiliates folder but if you are logged into the program in root, it also shows as www.mydomain/username so this may be a futile effort.  Example:  The program in root is a social network so when you login and click on your profile, or that of another user it goes to www.mydomain.com/username.  If you wanted to view pics of that user then www.mydomain.com/username/photos/ is the url.  

So is this just not possible?  

I do appreciate your efforts on this!

0
jeremycrussellCommented:
Ya, that make it very difficult, you would have to setup RewriteConds for all your affiliates to effectively *except* them out of the CMS.  Not sure if that's something you want to do.

Something that you can do is perhaps allow your affiliates to use http://username.mydomain.com...

You would need to have a DNS entry either for all the affiliates, or a wildcard entry. I.E.

*   IN   CNAME   www.mydomain.com 

Open in new window


Then you would have a rewrite like

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteCond %{HTTP_HOST} !^mydomain\.com
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com
RewriteRule ^(.*)$ http://www.mydomain.com/affiliates/%1/$1

Also

RewriteRule ^(.*) http://www.mydomain.com/affiliates/%1/$1 can be RewriteRule ^(.*)$ http://www.mydomain.com/affiliates/%1 if you don't need to worry about the uri for http://username.mydomain.com/some/uri

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Large_FarvaAuthor Commented:
Ok... well we really don't want to go the subdomain route so we will step back and rethink this thing.  Thanks for your help as you certainly helped sort it out!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.