Large_Farva
asked on
.htaccess rewrite
I am having trouble with my .htaccess:
For my affiliates to get credit, they need to send traffic to mydoman.com/affiliates/use rname
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:
and this is what I was told would do the job, without affecting my current folders and files:
There are some similar things in my current htaccess and I was not sure if they conflict or not.
Thanks!
For my affiliates to get credit, they need to send traffic to mydoman.com/affiliates/use
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>
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]
There are some similar things in my current htaccess and I was not sure if they conflict or not.
Thanks!
ASKER
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.
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.
ASKER
^^^it did not work.
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?
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?
ASKER
Ok..getting close.
Here is what I have now:
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.
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
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.
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]
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]
ASKER
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!
So is this just not possible?
I do appreciate your efforts on this!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Should be
RewriteRule (.*) http://www.mydomain.com/affiliates/$1 [R=301,L]