I have a domain i.e www.domain.org and want to point it to a subfolder on my server. The main domain loads from /public_html and now, I want to load the domain from /public_html/domain2017.
I have researched various solutions on the web, but all I get is a redirect.
The redirect is not preferred because I end up with www.domain.org/domain2017 when I want to stay as www.domain.org but load the index.php file of www.domain.org/domain2017. Hopefully, this makes sense. Note: I have a WordPress installation within public_html/domain2017.
Below is example content of my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org$ [NC]
RewriteRule !^subdir/ /domain2017%{REQUEST_URI} [L,NC]
</IfModule>
Solution Attempt 1 Solution Attempt 2 Solution Attempt 3 Solution Attempt 4
I have tried all of the above links and they simply redirect my domain to the URL and does not prevent the URL in the address bar from changing
You can use the following htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteCond %{REQUEST_URI} !public_html/domain2017/
RewriteRule (.*) /public_html/domain2017/$1 [L]
Related
I have wordpress multisite with 2 sites: https://www.example1.com/ AND https://www.example2.com/
example2 site is a copy of example1, but 2 is new so I want to redirect all subsites to new domain.
Example: https://www.example1.com/data/post1243545 to https://www.example2.com/data/post1243545
Everything stays the same except domain
To answer the question as asked
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
per https://wpscholar.com/blog/redirect-old-domain-to-new-domain-via-htaccess/
However, you could simply configure the sites to use different domains and avoid having to use htaccess entirely as described in the following link.
https://wordpress.org/support/topic/change-domain-in-multisite/
I have two pages on my Wordpress site that need to be served as https; the rest is vanilla http. Pushing the whole site to https would involve a lot of database editing to avoid mixed content, so I'm looking to write an htaccess script to use a RewriteRule that will make the change just for those two pages.
The browser addresses for the two pages are like
http://example.com/draw/membership-login/ and
http://example.com/draw/membership-join/membership-registration/
Note they both contain the word 'membership' and no other page does (or so I believe), so I thought I'd write a rule to look for any REQUEST_URI containing 'membership'. I did this and put it before Wordpress's own script in .htaccess (.htaccess is in directory draw, the home directory for the Wordpress installation). It looks like this (only the first 4 lines are mine; the rest is WordPress's, except I've commented out their RewriteEngine On).
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} membership
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=302, L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
#RewriteEngine On
RewriteBase /draw/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /draw/index.php [L]
</IfModule>
# END WordPress
Result? All pages serve ok except the two membership pages, which serve as 404.
I guess it's good news in a sense, as the RewriteCond must be finding the membership pages, but the RewriteRule is clearly not delivering what I had hoped.
Any help much appreciated.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} membership(.+)
RewriteRule ^membership(.+) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The (.+) will match any character one or more times. A 301 redirect means that the page has permanently moved to a new location. A 302 redirect means that the move is only temporary.
I set my site up so that the root domain (flippinghousesforrookies.com) redirects to another site, but now the folders (flippinghousesforrookies.com/blog for example) I set up are also redirecting to the other site instead of their own index.php.
Any inside pages of the folders (flippinghousesforrookies.com/blog/contact for example) work fine, but not the homepage of each folder.
Not that I think it matters, but the site is set up as an add-on domain in it's hosting and each folder has a Wordpress install.
Here's the root's .htaccess:
RewriteOptions inherit
RewriteEngine on
#RewriteOptions inherit
# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini
# php_value mbstring.func_overload 4 # Required for PWSB support. Please do not uncomment this line.
RewriteCond %{HTTP_HOST} ^flippinghousesforrookies\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.flippinghousesforrookies\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/flippinghousesforrookies\.mykajabi\.com\/" [R=301,L]
And here is one of the folder's .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Any help would be appreciated! Thanks!
The code you used in your root .htaccess file is too long for the purpose you are trying to do.
You can do this in two ways.
a)
In the root .htaccess file put this code instead of the one you were entering:
RewriteCond %{REQUEST_URI} !^/blog
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://flippinghousesforrookies.mykajabi.com/$1 [R=301,L]
This code checks if there is /blog in the URL. If it is, then this rewrite rule will not be met and therefore it will not redirect the visitor to the new page. If there is nothing behind the url (so no subfolders) then the visitor will be redirected to the new page.
b) You can use only this part of the code. It redirects only the root folder to the new domain and it leaves all subfolders as they are.
RedirectMatch 301 ^/$ http://example2.com/
P.S. - Both work, but I added both solutions so you can adapt it to your own taste.
I'm trying to make a website where all users are redirected to a specific part in the domain so that they can see a "comming soon" page. While some ip addresses can still access the normal website so that they can see how it is going to look.
What I'm trying to do: create a wordpress website in the root of public_html, create a soon directory in public_html and redirect all users except a few ip's to http://www.domain.com/soon/index.html
My .htaccess looks as followed:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.2.3.4
RewriteRule (.*) http://www.domain.com/soon/index.html [R=302,L]
However whenever I go to the website to test it out it tells me:
ERR_TOO_MANY_REDIRECTS
Is there something I'm doing wrong in my .htaccess?
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule .? /soon/index.html [L]
Use this rule as your very first rule in your .htaccess:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^(1\.2\.3\.4|11\.22\.33\.44)$
RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$
RewriteRule !^soon/index\.html$ http://www.domain.com/soon/index.html [R=302,L,NC]
Variable REMOTE_ADDR matches client's IP in a web request.
RewriteCond %{REQUEST_FILENAME} !-f is needed to avoid redirecting for css/js/image files and /soon/index.html file.
I have a Wordpress multisite and I'm trying to direct everything from one of the sites to a completely different domain. Of the examples I've tried below, none of the redirects seem to do anything.
Options +FollowSymlinks
RewriteEngine on
#attempt one
Redirect 301 ^/multisite-one/.*$ http://newdomain.com/
#attempt two
RewriteRule ^multisite-one/$ http://newdomain.com/ [L,R=301]
#attempt three
RewriteCond %{REQUEST_URI} ^/multisite-one/(.*)$
RewriteRule ^(.*) http://newdomain.com/%1 [R=301,NC]
#attempt four
RewriteCond %{HTTP_HOST} ^multisite-one/$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/ [R=301,L]
#BEGIN Wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END Wordpress
A little bit about my setup:
The multi site is set up as having 2 homepages, one for multisite-one, another for multisite-two. There is no top level index page.
The multisites share page templates. The two sites are structured the same, they just contain different content (i.e. multisite-one is customer service, multisite-two is how-tos)
What I'm looking to accomplish:
http://mainsite.com/multisite-one/ redirects to http://newdomain.com/
http://mainsite.com/multisite-one/page2 redirects to http://newdomain.com/
http://mainsite.com/multisite-one/page8/pies redirects to http://newdomain.com/
http://mainsite.com/multisite-two/ does not redirect
http://mainsite.com/multisite-two/page2 does not redirect
http://mainsite.com/multisite-two/page8/tacos does not redirect
I've tried adding the above redirects within the Wordpress code as stated in this similar question. I've also tried all of these that seem relevant.
Note: I cannot use plugins because they are currently disabled and I do not have FTP access. I have to make these updates using the linux command line. Obviously this is a terrible situation.
There are lots of plugins you could use to help although i prefer to do it myself. I personally use:
Redirect 301 /subsite/ http://newdomain.com/
That works for me moving anything in the subsite folder to the newdomain address but preserving the rest of the URL.
If you want everything in subsite to move to http://newdomain.com/ and lose everything after that in the url then your second one should work
Figured it out after more googling and thinking about Ben Rhys-Lewis answer above.
RedirectMatch 301 ^/multisite-one(.*)$ http://newdomain.com/