I'm working a long time on this issue but I still didn't found a solution.
I have on a hosted sever a number of domains. My primary domain is directed to my public_html directory. For my second domain if have created a folder site2.
So www.site1.com is directed to public_html and www.site2.com is redirected to dir site2. So far no problem. Both sites seems to work ok.
But if a navigate to www.site2.com/extra_content the url that is shown is www.site1.com/site2/extra_content. If I use a traling slash on my url, the correct URL (www.site2.com/extra_content) is shown. So I added the solution for the trailing slash. But it doesn't work.
My .htaccess looks like this:
#ADD TRAILING SLASH TO DIRECTORY IF NONE EXISTS
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [L]
RewriteCond %{HTTP_HOST} ^(www)?site2.com$ [NC]
RewriteCond %{REQUEST_URI} !site2/ [NC]
RewriteRule ^(.*)$ /site2/$1 [NC]
Probably I missed something, so any help would be very much appreciated
Related
I have a site, and I would like to forward everything expect one folder and it's subfolders
I need this for my .htaccess on Linux Apache
so for example everything under
www.mysite.com
www.mysite.com/random_folder
www.mysite.com/random_folder2
goes to extra domain
www.extradomain.com
but
www.mysite.com/except_me_folder
www.mysite.com/except_me_folder/subfolder
www.mysite.com/except_me_folder/?anyrequest
have no redirection
I tried this
RewriteCond %{REQUEST_URI} !^/except_me_folder/?.*$ [NC]
RewriteRule (.*) https://extradomain/$1 [R=301,L]
I'm trying to rewrite URLs from old.domain.tld/project to domain.tld/subfolder/project using .htaccess in the project directory on the old server. I think I need to check for the host name so the rule only applies to the old server, even if the .htaccess file is also put on the new server.
I've tried the following .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.domain\.tld$ [NC]
RewriteRule ^(.*)$ https://domain.tld/subfolder/project/$1 [R=301,L]
This works fine for URLs like https://old.domain.tld/project/index.php?p=q (redirects to https://domain.tld/subfolder/project/index.php?p=q) but not for the URL without the trailing slash—https://old.domain.tld/project ends up being redirected to https://domain.tld. Very odd! How do I make this work for both types of URL?
I tried a rather different method to make this a generic redirect, that could be included even if the folder name wasn't project, but this has the same problem:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.domain\.tld$ [NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule . https://domain.tld/subfolder/%1 [R=301,L]
In a server-wide configuration, a slash is appended to all requests for index files, e.g. old.domain.tld/project is redirected to old.domain.tld/project/. Could this be causing a problem?
I have a primary/account domain (PrimaryDomain.com) and a couple add-on domains (AddOnDomain1.com and AddOnDomain2.com) I've recently switched the content from AddOnDomain1.com to AddOnDomain2.com and I want everything to redirect to the exact same location (folders, files, images, etc.)
Here's what I have in .htaccess of my public_html folder (for PrimaryDomain.com):
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.AddOnDomain1\.com$
RewriteRule (.*) http://AddOnDomain2.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^AddOnDomain1\.com$
RewriteRule (.*) http://AddOnDomain2.com/$1 [R=301,L]
It trys to redirect but here's what happens (with an image as an example). When I enter:
http://AddOnDomain1.com/img/logo.png
It redirects to:
http://AddOnDomain2.com/AddOnDomain1/img/logo.png
Notice how it adds that folder (in bold)?...which of course is the add-on domain directory name. Anyone aware of a fix for this scenario?
I am not a friend of htaccess and have bumped into a problem I can't seem to google a solution for. So here is hoping that you guys can help.
I have a multisite instalation where I am trying to redirect all trafic to mydomain.com/anothersite (and all sub folders and query strings) to anothersite.com and at the same time have all requests to anothersite.com rewrite to requesting the server to look up the anothersite folder.
Basically the server folder setup is as follows:
in the root we have a website
in the root we have a folder "anothersite" that contains another site
So all requests to mydomain.com should show the root folder while all requests to anothersite.com should get rewritten.
Hope that made sence
Here is what I have (it almost works but not quite)
RewriteEngine on
RewriteBase /
RewriteRule ^mydomain\.com/anothersite(.*)$ http://anothersite.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?anothersite.com$
RewriteRule !^anothersite/ anothersite%{REQUEST_URI} [L]
problems are that requests to mydomain.com/anothersite/someFolderOrQuerystring isn't redirected, while mydomain.com/anothersite/ is
Hope it made sence
(btw: if someone can point me in the direction of a book, that will make me a master of the mysteries of the htaccess file that would be a sweet bonus
Have this rule in site root .htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^anothersite(/.*)?$ http://anothersite.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?anothersite\.com$ [NC]
RewriteRule !^anothersite/ anothersite%{REQUEST_URI} [L,NC]
Make sure you don't have any .htaccess under anothersite/ folder.
I am new to htaccess configuration but I have been reading and researching for awhile.
I have a mobile subdomain which I wish to fetch images located on my main domain. I am unsure as how to get it to work. My current code is:
RewriteCond %{HTTP_HOST} ^m\.\.website\.com [NC]
RewriteRule ^/avatar/(.*)$ http://www.website.com/avatar/$1 [P]
The image directory looks like this:
/avatar/thumbnail/image.jpg
/avatar/preview/image.jpg
/avatar/full/image.jpg
However, when I try to access m.website.com the images do not load.
Can anyone tell me what I am missing.
Any feedback would be greatly appreciated.
Remove leading slash from your rule and also take out extra DOT from host name condition:
RewriteCond %{HTTP_HOST} ^m\.website\.com [NC]
RewriteRule ^(avatar/.*)$ http://www.website.com/$1 [P,L]
This assumes you have mod_proxy enabled and working.