I want to add a landingspage on my website. The landingspage is on a subdirectory.
Im using a .htaccess file to redirect from the subdirectory.
The .htaccess contains:
RewriteEngine On
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY}%{TIME_HOUR}%{TIME_MIN} <201604071200
RewriteRule ^$ /test [R=302,L]
So with this script, site will redirect to the http://example.com/test untill seventh of April, 2016, 12:00.
Now I want that AFTER seventh of April, 2016, 12:00, the domain http://example.com/test redirect to the home domain http://example.com.
How can I achieve this?
Yours,
L
Related
I am trying to use htaccess to redirect ALL pages from a domain to a specific page on a new domain. Yes, I completely understand we will loose SEO value this way.
I currently have a cpanel redirect that makes this url:
https://www.kiss1047.net/
go to this
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
but that doesn't get any of the internal pages to redirect. I would also like all internal pages (here is an example):
https://www.kiss1047.net/listen-live
to also go to:
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
I have tried a few things, but they always carry over the page url, ie above /listen-live/
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/listen-live/
and that results in a 404.
is there some htaccess magic i can employ here?
In your .htaccess file .. Make a single entry that looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://mytown-media.com/stations/kiss-104-7-kxnc-fm/ [R=301,L]
This will direct ALL TRAFFIC (.*) to your other website .. Regardless of file name or directory .. And will not append the file/directory to the end of the URL .. IE listen-live
This is a 301 Permanent redirect [R=301,L] .. Which means once followed by Google, will be indexed as such .. Also will cache in users browsers so that the browser remembers the 301 instead of bouncing between websites as well.
This command in .htaccess redirects every page of your old domain to new domain's one specific URL.
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L]
For your case:
RewriteEngine on
RewriteRule ^(.*)$ https://mytown-media.com/stations/kiss-104-7-kxnc-fm/ [R=301,L]
In result:
https://www.kiss1047.net/listen-live
will be redirected to:
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
I was just wondering how to design a website so you can have the addresses for the different pages as I indicated in the title.
So how do you get x.something.com rather than something.com/x?
Add a DNS entry with value of * and url as same as the www url or blank field's url(both which are in fact same and should be)
Then add these lines to your .htaccess file at the root www folder
RewriteCond %{HTTP_HOST} ^x.something.com$
RewriteRule ^.*$ http://www.something.com/x [R,L]
Remember that x is your subdomain and something.com is your domain and besure you have the .htaccess file in the root www folder.
For more just comment...
Thanks
I would really appreciate help with the following 301 Redirect using Apache .htaccess as I am stuck on how to do this:
I need to convert:
http://blog.domain.com/2015/03/filename.html
to:
http://www.domain.com/blog/filename/
There are many to do from the original file structure. The year and month that make up the original URL, change and go back each month and for several years. i.e. 2015/03, 2015/02, 2015/01, 2014/12 etc...
The ending filename.html needs to be the name of the new directory name without the ending .html and adding a closing '/'
This is what I have so far, but it doesn't work:
RewriteRule http://blog.domain.com/([0-9]+)/([0-9]+)/(.*)\.html$ http://www.domain.com/blog/$3 [R=301,L]
You can't include the http://domainname/ part of the URL in the regex of a rewrite rule, only the 2015/03/filename.html part is used for any matching.
You could try using mod_alias instead:
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/([^/.]+)\.html$ http://www.domain.com/blog/$1/
Or if you already have rewrite rules, better to stick with mod_rewrite:
RewriteCond %{HTTP_HOST} ^blog\.domain\.com$ [NC]
RewriteRule [0-9]{4}/[0-9]{2}/([^/.]+)\.html$ http://www.domain.com/blog/$1/ [L,R=301]
I have a website on a test server and I want to rewrite URL for this website because it is very long
I wish our visitors instead of entering this URL:
http://staging.company.fr/site2.it/s...oject2/public/
enter this URL:
www.monsite.com
I created a file. htaccess:
RewriteEngine On
RewriteRule ^/~(.+) http://www.monsite.com/~$1 [NC,L]
but does not work
While in .htaccess mod_rewrite doesn't match leading slash in a URL since it is applied per directory. Therefore following should work:
RewriteEngine On
RewriteRule ^(.+)$ http://www.monsite.com/$1 [L,R=301,NE]
This will redirect every URL in your existing domain other than home / to monsite.com
Reference: Apache mod_rewrite Introduction
I'm restructuring a web site with a great deal of content currently parked at URLs that look like this.
http://string.domain.com/year/month/dd/string-pulled-from-title
For various reasons, I'd like to park all new content at URLs that looks like this
http://www.domain.com/blogs/string/year/month/dd/string-pulled-from-title
I'd like to make the change for future content, but don't want all the old stuff to go 404.
I believe a 301 redirect rule in my htaccess will do the trick, sending all referred traffic coming in through old links to the new formats.
But what should this rule look like? I've read a few tutorials but haven't found this exact case in any examples.
Note, I don't want to do this for all subdomains, only for about 10 specific ones. So if someone could help me figure out one of these, then I can copy paste it 10 times in my htaccess for each subdomain and be set.
Drop this into the .htaccess file of the old site (adjusting the domain to your actual one):
RewriteEngine On
RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]
This will grab this part of the URL at the old site:
year/month/dd/string-pulled-from-title
and redirect it to the new site under the new location:
blogs/string/year/month/dd/string-pulled-from-title
Alternatively, if you want something a little more variable like, without having to custom fix each .htaccess, drop this in the file for each subdomain instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
If you're redirecting to the same domain, and it includes the www, adjust the rewrite rules to the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]
Note the second RewriteCond which checks to make sure that the URL requested does not include the leading www, which may lead to an endless redirect if the destination URL itself includes www and would try and redirect that subdomain as well.
%1 grabs the first capture group from the line above.
$1 references the first capture group on the same line.