How to do IP Canonicalization Test in .htaccess file - seo

How to do IP Canonicalization for my website.
I have tried some like this
RewriteCond %{HTTP_HOST} ^00.009.198.252
but its not working.
Please help me
RewriteRule (.*) http://www.freelancerabraham.com/$1 [R=301,L]
url of my website- www.freelancerabraham.com/

If you are using appache you can change 'allow from all' to "allow from 'YOUR HOST'"

Related

How to use .htaccess file to get the subdomain?

I want to redirect https://aaa.subdomain.example.com/path to https://subdomain.example.com/aaa/path
But how to do that with apache .htaccess file?
I tried this, however, it didn't work :(
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.subdomain\.example\.com [NC]
RewriteRule .* https://subdomain.example.com/%1/${REQUEST_URI}
Important: the following instructions are for information purposes only. You may need to change the code so that it works in your situation.
Using your FTP software or our FTP Manager, add and adapt the following code in the .htaccess file located in the root of your Website:
RewriteCond %{HTTP_HOST} ^(.*).domain.com [NC]
RewriteCond %{DOCUMENT_ROOT}/%1/ -d
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/1/?
RewriteRule "^(.*)$" "%{DOCUMENT_ROOT}/%1/$1" [L]
Explanations for the third line: [https://stackoverflow.com/a/15981056][1]
In the first line replace:
domain with your domain name
com with your domain name extension (ch, fr, etc.)

.htaccess redirect to subdomain url with hash

I'm trying to redirect a site with the following url structure:
https://example.com/2021/about
to
https://2021.example.com/#about
https://example.com/2021/visit
to
https://2021.example.com/#visit
how can i do this?
i tried adding this to the /about directory in the original domain:
RewriteEngine on
RewriteBase /
RewriteRule (.*) https://2021.example.com/#about [R=301,NE, L]
but what i got after the redirect was
https://2021.example.com/#about2021/about
which is not right. any help is appreciated
[EDIT] i only want to apply this to some folders, like /2021/about and 2021/visit
You may use this redirect rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com) [NC]
RewriteRule ^(20\d{2})/(.+?)/?$ https://$1.%1/#$2 [R=301,L,NE]
Make sure this is your topmost rule in .htaccess and you clear your browser cache before testing this new rule.
Could you please try following, written based on your shown samples. Please make sure to clear your browser cache before testing your URLs. Following will only be applied to 2021/about OR 2021/visit uris.
RewriteEngine ON
RewriteCond %{HTTP_HOST} (example\.com) [NC]
RewriteRule ^(2021)/(about|visit)/?$ http://$1.%1/#$2 [R=301,NC,NE,L]

301 redirection in htaccess not working

I have and issue when I'm trying to redirect my old domain to my new domain. Things look like that right now:
newdomain.pl <- is connected to blogger account
olddomain.pl <- is connected to server with .htaccess file (before it was connected to blogger account)
I would like it to work like that : olddomain.pl/subdomain -> redirect to newdomain.pl/subdomain. But whatever I try to put into my .htaccess file it's redirecting my old site to main page of newdomain (newdomain.pl). I've tried codess like that:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomain.pl[nc]
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [r=301,nc]
but it's also redirecting to main page of new domain. Only when I put:
RedirectRule / http://www.newdomain.pl
It's redirecting to http://www.newdomain.plsubdomain <- but there is slash "/" missing between the newdomain name and subdomain. Unfortunately when I write this:
RedirectRule / http://www.newdomain.pl/
it's redirecting to main domain page http://www.newdomain.pl, so it's not working. I don't know what can be wrong, I'm fighting with that three days already. Does anyone have an idea where can be the problem? Maybe there is something wrong with hosting that I bought? Thank you in advance for any response
Regards, Pawel
Try next:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R]
For only redirecting queries without direct redirecting to domain remove R flag.
Try this in olddomain/.htaccess :
RedirectMatch ^/(.*)$ http://newdomain.com/$1
Ok I found a solution. The problem was not including "www" in RewriteRule. When I changed it, it worked. I'm putting the code that worked for me below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain.pl$
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^olddomain.pl$
RewriteRule ^(.*)$ http://www.newdomain.pl/$1 [L,R=301]
Thank you everyone!

htaccess rewrite rules for subdomain to fetch image directory from main domain

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.

How to permanently redirect a url with a .htaccess file?

I need to do a 301 permanent redirect from
http://www.example.com/search.php?search=samplesearch
to
http://www.example.com/used/search.php?search=samplesearch [301]
Any help greatly appreciated. Thanks
I think you'll find your answer if you search stackoverflow for 'redirect htaccess 301'. If you want to see how it's done. Use your cPanel to create a permanent redirect and then open your htaccess file with a text editor or cpanel filemanager to view the code. Then you'll know how to mod the htaccess manually if you need to.
Use RewriteCond with %{THE_REQUEST}
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET \/search\.php\?search=samplesearch\ HTTP/ [NC]
RewriteRule ^(.*)$ /used/search.php?search=samplesearch [R=301,L]
For more information about mod_rewrite variables this site may help you:
http://www.askapache.com/tools/mod_rewrite-variables-cheatsheet.html