I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.
Related
I have one domain that used to have its own WP installation, say www.aaa.example.
Now the content of this has been included in a different domain in a sub-page, say bbb.example/aaa-subpage/.
Also, the old domain www.aaa.example has a DNS A record pointing to the WP Server of bbb.example.
What I want now is, that all calls go to www.aaa.example/* should be redirected to bbb.example/aaa-subpage/ no matter which sub-page on aaa.example was used. So everything should go to one sub-page in the new domain.
I have tried some 301 redirect plugins but so far no chance... all calls from aaa.example simply go to the top-level page of bbb.example.
To redirect requests to aaa.example/<anything> to bbb.example/aaa-subpage/ you would need to add the following mod_rewrite directives to the top of the root .htaccess file. Crucially, it must go before the WordPress front-controller (ie. before the # BEGIN WordPress comment marker).
# Redirect "aaa.example/<anything>" to "bbb.example/aaa-subpage/"
RewriteCond %{HTTP_HOST} ^(www\.)?aaa\.example [NC]
RewriteRule ^ https://bbb.example/aaa-subpage/ [R=301,L]
You do not need to repeat the RewriteEngine directive that should already appear later in the file (in the WordPress section).
Test first with a 302 (temporary) redirect to avoid caching issues.
You will need to clear your browser cache before testing.
Try this line in the .htaccess:
RedirectMatch ^/$ /aaa-subpage/
could anyone help me please with the code that I need to insert in my blog's .htaccess to redirect everything from:
https://www.example/blog/wp-json/WHATEVERcomesHERE
to:
https://www.example.com/blog/
The .htaccess file resides in https://www.example/blog/ (since example.com is another story, and WP is installed on /blog/). Thanks!
This should do what you need. If you want to pass the value of "WHATEVERcomesHERE" in the redirect you can do so using $1 in the URL you want to redirect to (i.e. https://www.example.com/blog/$1).
RewriteEngine on
RewriteRule ^blog/wp-json/(.+)$ https://www.example.com/blog/ [R=301,L]
Also, the current rule would redirect /blog/wp-json/sada but not /blog/wp-json/. If you want it to redirect when there isn't anything after wp-json then change (.+) to (.*)
Here is a simple redirect, You can add this code at the end of your .htaccess file
RewriteEngine On
RewriteRule ^blog/wp-json/(.+)$ https://www.example.com/blog/ [R=301,L]
Please keep in mind that a small mistake in your .htaccess code can make your WordPress site inaccessible, and it may start showing Internal Server Error.
That’s why it is important that you backup your .htaccess file before making any changes.
Another way (Recomended)
Create Redirects in WordPress using Plugins
You can use Redirection plugin.
Install and activate the plugin. Once activated, visit Tools » Redirection to setup your redirects.
Also Simple 301 Redirects , it makes 301 Redirects simple. Simply install and activate the plugin and then visit Settings » 301 Redirects to add your URLs.
I've searched around but no one has the exact issue as me, I can't figure out how to do this without messing up the site.
-My website is WordPress.
-Vultr VPS with Server Pilot
-Currently the site is behind cloudflare and this all works.
Issue: I have an entire version of the website still browsable using the server IP and I can't figure out how to 301 redirect it.
Example if you happen to go to my website xxx.x.xx.xx then you can browse the entire website without ever being redirected, the query strings and everything shows in the address bar example:
http://xxx.x.xx.xx/category/page/?utm_source=aa&utm_medium=bb&utm_campaign=cc
Someone could browse the entire site like this, I do not want this I want to redirect it to my domain. In WordPress general settings I do have the Site URL and WordPress URL set to my domain name but I don't know why this is happening.
I can't give examples of what I've tried because they all failed and I had to delete them from my .htaccess file, basically, I want to 301 redirect any request coming to the IP and send them to the domain of the site carrying over their query string and everything, help is really appreciated.
Did you try this in your .htaccess file?
RewriteEngine On
RewriteBase /
Redirect 301 /old_page1/ http://example.com/new_page1
Redirect 301 /old_page2/ http://example.com/new_page2
Fixed it by using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xx\.xx\.xxx\.xxx
RewriteRule (.*) https://example.com/$1 [R=301,L]
</IfModule>
Dot's must be escaped and the query strings get carried along just fine, be sure to leave the trailing slash as it's displayed above or else your page might appear like this: https://example.compage/subpage
Leaving the trailing slash in the rewrite rule will prevent that so it would be: https://example.com/page/subpage
I want to permanent redirect some .htm page from subdomain to main domain WordPress page, for this I am using this code
Redirect permanent /cat/FSBO76.htm http://www.example.com/cat/my-favorite/
But I am getting a problem normally my WordPress page working fine but when I click on old link its redirect with trailing query string and showing page not found error.
http://www.example.com/cat/my-favorite/?cat=FSBO76
Can anyone tell me how can I redirect without path and query string? or any way to solve this problem.
I already try with Redirect 301 also.
EDIT: Its only happening for .htm files, all other files and directory redirecting properly.
This sounds like maybe mod_alias (Redirect) and mod_rewrite is interferring with each other. If you already have wordpress rewrite rules in your htaccess file, you need to stick with mod_rewrite instead of using mod_alias here. Try using something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteRule ^cat/FSBO76.htm$ http://www.example.com/cat/my-favorite/ [L,R=301]
where "subdomain.example.com" is your subdomain.
For my site: http://www.indiacustomercare.com which one is the canonical url with www or without www?
I've not changed any settings.
I remember that I changed this to www. in one for my previous drupal-6 website but I've forgotten it now(I did not change .htaccess).
So if I access my site as http://indiacustomercare.com then all pages seem to be without www ( except for those in the footer which are hardcoded with www...)
Similarly for when I access my site as http://www.indiacustomercare.com all web pages seem to have www prefix.
So what is my site's default www or without www?
Yes, in Drupal .htaccess there are pre-defined settings for this. Go to line 90-97, choose which domain you want to use (with or without www), uncomment the appropriate lines and add there your domain.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
This one redirects from example.com to www.example.com.
There is also the opposite direction below.
You choose, but it's considered best practice to go with either one or the other, and not leave both available. If you set up a 301 Redirect, it is nicer for search engines.