Basically, i'm trying to redirect all the pages like this
http://www.example.com/page-test-1/page-test-1-2/page-test-1-2-3.html
or
http://www.example.com/page-test-1/page-test-1-2.html
or
http://www.example.com/page-test-1/page-test-1-2/
to the home page :
http://www.example.com/
Here's what I've trying :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.exmaple.com/([^.]+)/
RewriteRule ^(.*) http://www.exmaple.com/ [QSA,L,R=301]
And here's the tester I'm using : http://htaccess.madewithlove.be/
Any way I can do this ? Much appreciated.
This rule should work for you:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.exmaple\.com$ [NC]
RewriteRule ^page-test-1/.+ / [L,R=301,NC]
This will catch anything that is not /anypage.html and redirect it. You need to set the RewriteCond on the REQUEST_URI not the HTTP_HOST.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/([^/]*)\.html$
RewriteRule ^(.*) http://www.example.com/ [QSA,L,R=301]
Related
I have hosted opencart website on subdomain beta.mydomain.com with ssl cirtificate installed.
I want to force https and www . when someone types beta.example.com should take them to https://www.beta.example.com
I tired following .htaccess entries
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example.com\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteBase /
I dont understand whats going wrong here. thanks in advance.
Well, the domain you're using in your example is not beta.example.com it's example.com you should change it to the domain you require. Something like:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.beta\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.beta.example.com/$1 [L,R=301]
RewriteBase /
What do you use the RewriteBase for?
I personally like to use the following process:
Redirect to www
Redirect to https
Something like:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
In case you haven't already checked it, this GitHub Repository has some useful info on .htaccess.
The easiest way is to update your config.php file in your home directory.
I don't have it in front of me, but you'd want to change your HTTP and HTTPS url to "https://www.beta.example.com".
for htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://www.yoursite.com%{REQUEST_URI} [NS,R,L]
alternative htaccess code
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
for php redirect
Open index.php file
find
<?php
add after
if (substr($_SERVER['HTTP_HOST'], 0, 4) === 'www.') {
header('Location: http'.(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on' ? 's':'').'://' . substr($_SERVER['HTTP_HOST'], 4).$_SERVER['REQUEST_URI']);
exit;
}
I want convert links to another domain
From this : www.old.net/upload/namefolder/namefile.mp3
To : www.new.net/upload/namefolder/namefile.mp3
using .htaccess
How can I do this?
Try this hope it will work fine.
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(?:mp3)$
RewriteCond %{HTTP_HOST} old\.net [nc]
RewriteRule ^(.*)$ http://www.new.net/$1 [R=301,L,QSA]
You can use something like:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]
RewriteRule ^(.*)$ http://www.new.net [R=301,L]
my questions are simple, how can I redirect this kind of urls :
www.domain.com/?page_id=25&ID=46
to :
www.anotherdomain.com/
When I try with this :
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "http\:anotherdomain.com\" [R=301,L]
The url is redirected to http:anotherdomain.com\?page_id=25&ID=46
And another redirection I need is to redirect this :
blog1.domain.com to anotherdomain.com knowing that there are multiple blocks.
Thanks for any help,
Best regards.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www|blog1)\.domain\.com$ [NC]
RewriteRule ^ http://www.anotherdomain.com/? [R=301,L]
And I have a lot of subdomain:
sub1.abc.com, sub2.abc.com,.., subn.abc.com with the same directory: true-dir-1, true-dir-2, true-dir-3
I want to
If url not contains (true-dir-1, true-dir-2, true-dir-3) then redirect to subdomain
For example:
sub1.abc.com/false-dir redirect to sub1.abc.com
sub2.abc.com/false-dir redirect to sub2.abc.com
Pls help me use .htaccess to redirect it..
Thanks so much!
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.abc\.com$ [NC]
RewriteRule !^true-dir-1 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub2\.abc\.com$ [NC]
RewriteRule !^true-dir-2 / [L,NC,R=302]
RewriteCond %{HTTP_HOST} ^sub3\.abc\.com$ [NC]
RewriteRule !^true-dir-3 / [L,NC,R=302]
You can use that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.abc\.com$ [NC]
RewriteRule !^%1 / [L,NC,R=302]
Change [R=302] for [R=301] when test work well.
ive this rules at htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
issue happend when redirect warcraft its redirect to
http://www.site.com/home/site/public_html/www.site.com/forumdisplay.php?f=480
any tip ?
I suppose you want to redirect it to http://www.site.com/forumdisplay.php?f=480
If so put it in your .htaccess file:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^warcraft$ http://www.site.com/forumdisplay.php?f=480 [R=301,NE,NC,L]
You must provide the full URL including protocol in your rule, in this case http://www.site.com/.....