I'm sure some way or another this question is as old as the method itself but my challenge was to make
site.eu/subfolder/subfolder appear as subdomain.site.eu
I managed to figure that out on my own and got it to work. The code is following:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.site.eu [NC]
RewriteRule ^(.*)$ /subfolder1/subfolder2/%{REQUEST_URI} [R=301,P,NC]
The following issue is that in that adress, there is an app where you must log in.
After logging in, it will show subdomain.site.eu/subfolder1/subfolder2/content1
I have tried about 2-3 days to fix this but to no avail. I really hope somebody could help me out on this. IF there is any other info needed, please tell.
You can use this in root .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.site\.eu$ [NC]
RewriteRule ^((?!subfolder1/subfolder2/).*)$ /subfolder1/subfolder2/%{REQUEST_URI} [L,NC]
Related
I seearched a little bit but seems like I cant find proper answer for my problem. I have 4 domains and I need to redirect 3 domains (and some of their pages) to new one.
https://www.domain1.com/ to https://www.domain4.com/music/domain1/
https://www.domain2.com/ to https://www.domain4.com/music/domain2/
https://www.domain3.com/ to https://www.domain4.com/music/domain3/
and i need it for some pages also, for example:
https://www.domain1.com/about.php to https://www.domain4.com/domain1/about/
Can someone help me how to do this in htaccess?
Thanks in advance
Could you please try following, written as per shown samples. After placing these Rules into your .htaccess file, before testing make sure you clear your browser cache.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain[123])\.com [NC]
RewriteCond %{REQUEST_URI} ^/?$
REwriteRule ^(.*)$ https://www.domain4.com/music/%1/ [NE,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain[123])\.com [NC]
RewriteCond %{REQUEST_URI} ^/(about)\.php/?$
REwriteRule ^(.*)$ https://www.domain4.com/%1/%2/ [NE,L]
Good morning all,
When I do a search for the name of my site on google I end up with lots of links like mysite.com/?page=1
mysite.com/?page=2
Etc.
I would like to redirect 301 of these links which ends in mysite.com/?page=X
to monsite.com
Because I am afraid that Google will see it as duplicate content knowing that it displays all the home page of my site ...
I tried
RewriteCond %{QUERY_STRING} ^page=1(&|$) [NC]
RewriteRule ^(mysite)/?$ /$1? [R=301,L]
which doesn't work on my side.
Could you help me ?
Thanks in advance,
To redirect such requests this should be what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)page=\d+(?:&|$) [NC]
RewriteRule ^/?$ / [QSD,R=301,END]
Or a more general example which preserves given a path
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)page=\d+(?:&|$) [NC]
RewriteRule ^ %{REQUEST_URI} [QSD,R=301,END]
Keep in mind however that even with such redirection you still have the issue that somewhere those references are generated. Google does not make them up. So to fix the actual issue and not just a symptom you will have to find the actual issue...
Need to know how to show the full URL of my website, I would need to pass:
www.ejemplo.com.ar to www.ejemplo.com.ar/index.html
I've tried all types of redirect and rewrite, but none worked out. I hope you can help me.
Over Apache2
This is a pretty easy solution, a search would have revealed it easily. Try this.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?ejemplo\.com\.ar$
RewriteRule ^$ http://%{HTTP_HOST}/index.html [L,R=301]
My problem is very simple.
I have several folders in my root:
[folder1]
[folder2]
[folder3]
And my domain is something like: http://johndoe.net
I keep my website in [folder1], so basically I access it by typing http://johndoe.net/folder1
My goal is this:
I want to type http://johndoe.net and I get the content of http://johndoe.net/folder1 but the address has to remain http://johndoe.net
I want to type http://johndoe.net/folder1 and see my website, but my address has to change to http://johndoe.net
Seems easy enough, but I failed finding the solution after several hours of searching.
So far, the only thing I achieved is redirecting from http://johndoe.net to http://johndoe.net/folder1 by placing this bit of code in my .htaccess in my root:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "http\:\/\/johndoe\.net\/folder1\/" [R=301,L]
When I type http://johndoe.net, I get http://johndoe.net/folder1 in my address bar
but what I need is my address to remain http://johndoe.net
Could anyone help me with this?
You're going to use two .htaccess files to solve this problem. Here's what you put in them, and where they go.
File #1. This goes in your base folder (the one that contains [folder1],[folder2], etc)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((www\.)?johndoe.net)$
RewriteRule ^(.*)$ /folder1/$1 [L]
File #2. This goes in [folder1]
RewriteEngine Off
Try something like this
RewriteRule ^(.*)$ /folder1/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "\/folder1\/" [L]
you need internal rewrite, So it's enough to rewrite / to /folder1/
I'm sorta a noob at these things but I'm trying to make a simple virtual subdomain with .htaccess. I have wildcard enabled and after lots of digging, this is what I've come up with:
rewriteEngine On
rewriteCond %{HTTP_HOST} !^$
rewriteCond %{HTTP_HOST} !^(www\.)?khpedia\.com$ [NC]
rewriteCond %{HTTP_HOST}<->%{REQUEST_URI} ^(www\.)?([^.]+).*<->/([^/]+) [NC]
rewriteCond %2<->%3 !^(.*)<->\1$ [NC]
rewriteRule ^(.+) /%2/$1 [L]
My directory is setup as
-root
--wiki
----index.php
--test
Right now when I travel to wiki.khpedia.com, I get a page not found. When I travel to wiki.khpedia.com/index.php, it travels to wiki.khpedia.com/wiki/index.php. I am somehow also able to access wiki.khpedia.com/test. If it doesnt seem obvious yet, I want to be able to go to wiki.khpedia.com/index.php and see wiki.khpedia.com/wiki/index.php but not in my address bar. Sorry for the text block and thanks for the help.
This works on the Apache side:
RewriteCond %{HTTP_HOST} !^www\.khpedia\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.+).khpedia\.com$ [NC]
RewriteRule ^(.*) /%1/$1 [L,QSA]
But you're wiki software might make up it's own mind about redirects / urls.
RewriteCond ^(.*)$ /wiki/$1 [L]
I'm confused about where subdomains come into your question. Could you give some examples of URLs you want to access in the browser and what they should point to at the server?
EDIT | Ah, I see now, Wrikken's answer handles the subdomains correctly :)