I want to disallow https version for landing page only & that is 'index.php'. However when I visit the website 'www.example.com', index.php is not called & so .htaccess file doesn't get what it is.
Until now I was using below code:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^index\.php$ http://www.example.com [L,R=301]
If I do this:
RewriteRule https://www.example.com http://www.example.com [L,R=301]
This doesn't seem to work. Any help?
Also I want to redirect particular landing page only, because for a login & such pages I redirect it to https version.
This should work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^$
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^$ https://example.com/index.php [L,R=301]
Like this you redirect people who only visit your site over http://example.com to http://example.com/index.php. After that i've just added your already existing .htaccess code, which should work properly now because index.php is called
Related
I want to redirect all pages (including subdomains) of an old domain to a single page on the new domain. All pages will be redirect to the same page on the new domain.
I have countless subdomains on the domain I want to redirect. For this reason I need a dynamic code that redirects all pages, because there is no way for me to find all subdomains.
I have pages like this:
old.com
old.com/page1
old.com/page2
sub.old.com
sub2.old.com
sub2.old.com/page
I tried all variations of this code but the subdomains won't redirect:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^old\.com$ [NC]
RewriteRule ^(.*)$ https://new.com/we-moved/ [R=301,L]
If you are using cPanel, Directly use the Redirect Option. IF you want to edit .htaccess file, Checkout my Code:
RewriteCond %{HTTP_HOST} ^clsh\.ga$ [OR]
RewriteCond %{HTTP_HOST} ^www\.clsh\.ga$
RewriteRule ^/?$ "https\:\/\/url\.cloudmate\.in\/" [R=301,L]
This htaccess redirects https://clsh.ga to new Domain https://url.cloudmate.in .
If your htaccess does not redirect then also, try enabling mod_rewrite.c
This should work for you:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} (?:^|\.)old\.com$ [NC]
RewriteRule ^ https://new.com/we-moved/? [R=301,L]
(?:^|\.)old\.com$ will match root domain or any subdomain.
? will discard any query string in redirect.
If user goes to URL
http://example.com
The server does a 302 Moved and goes to http://example.com/en/home/my-page.html
What I want is if URL is
http://example.com/en/home/my-page.html
The browser should just show http://example.com/en/
I've tried with .htaccess like so:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^en/home/my-page\.html
RewriteRule ^en/ /en/home/my-page\.html [R=301,L]
RewriteRule ^index.php$ en/home/my-page\.html [L,R=301]
but it does nothing. What am I doing wrong?
Your regex patterns are wrong.
You can use these rule in site root .htaccess:
RewriteEngine on
# externally redirect /en/home/my-page.html to /en/
RewriteCond %{THE_REQUEST} \s/+en/home/my-page\.html[?\s/]
RewriteRule ^ /en/ [R=301,L]
# internally rewrite /en/ to /en/home/my-page.html
RewriteRule ^en/?$ en/home/my-page\.html [L,NC]
Don't forget to clear your browser cache before testing this change.
This code will redirect user hitting
http://example.com/en/my-page.html
to
http://example.com/en/
and than will internally redirect thr request to index.php (you can substitute parameter with the directory where index.php is located or just remove it if it is in the main dir)
RewriteRule ^en/my-page\.html$ /en/ [L,R=301]
RewriteRule ^en/ /<dir>/index.php [L]
I have a new WordPress site, example.com, with the old Drupal site archived at archive.example.org. Many files on the old site had a URL like so (ex: example.org/files/foo.pdf), but all those links out there in the internet are breaking because all those file downloads need to be redirected to archive.example.org/files/foo.pdf.
Can creating redirects (I'm guessing .htaccess is the best bet) work for file downloads as well? Is there a simple redirect to send all old links to the archive subdomain?
I have tried:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.org%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
...with no luck so far.
Thanks for any help!
If you want to redirect all files/* requests to the new domain and keep everything else from WordPress, you need a condition for the rule, which checks for files
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.com%{REQUEST_URI} [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.
I am trying to redirect every folder from domain.com to it's subdomain.
Examples:
domain.com/a -> a.domain.com
domain.com/b -> b.domain.com
domain.com/about -> about.domain.com
So basically, every folder redirected to it's subdomain. For the first example, folder a contains index.html. When I browser to domain.com/a it should redirect the url to a.domain.com but use the index.html file from the a folder.
My current htaccess looks like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteCond %{REQUEST_URI} !^/%1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /%1/$1
RewriteRule ^(/)?$ %1/index.html [L]
What works
For now, if I navigate to test.domain.com, it's working, it's taking the index.html file from the test folder. If I go to domain.com/test it's still working, but I want to disable this. I want to redirect domain.com/test to test.domain.com as well, but still use the index.html files from the test folder.
Another thing that is in the htacces file is to redirect www to non-www.
Any suggestions would be appreciated.
EDIT:
Forgot to mention that I've tried to add this line:
RedirectMatch 301 ^/test/(.*)$ http://test.domain.com/$1
It's doing the redirection from domain.com/test to test.domain.com/index.html, but it's not loading the page right, I get an error (Page isn't redirecting properly).
keep like
RedirectMatch 301 ^{RELATIVE PATH}$ {ABSOLUTE_PATH}
Here is my directory structure
main site:-
www.magentosite.com
Wordpress site:-
www.magentosite.com/wordpresssite
And Here is my htaccess rule for redirect. If User goes to wordpress site then they will redirect to magentoSite.
RewriteCond %{REQUEST_URI} !^WordpresSITE/
RewriteRule .? http://www.MagentoSITE.com/ [L]
PROBLEM
Above should work as it is but I want to put if user goes to admin side of wordpress then yes they should not redirect. In short www.magentosite.com/wordpresssite/wp-admin/... should not redirect.
The below code should go inside the .htaccess on the WordPress folder:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/wordpresssite/(wp-login\.php|wp-admin) [NC]
RewriteRule ^ http://www.MagentoSITE.com/ [R=302,L]
Basically what I am doing is if the URL start with:
www.magentosite.com/wordpresssite/wp-login.php
Or starts with:
www.magentosite.com/wordpresssite/wp-admin
It should not redirect, if it doesn't then it redirects.