I am new to WordPress and I have uploaded my files into two domains, a main domain and a sub domain. In my sub domain I want to show my main domain images by htaccess. I have used below codes but couldnot get any success.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(files/profile_image/.*)$ http://example.com/$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://dev.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
I have used above code but couldn't get any success. Can I get any help?
I know this is old, but posting an alternative simple method here:
RedirectMatch 301 /wp-content/uploads/(.*) https://live-site-to-redirect-from.com/wp-content/uploads/$1
I do this all the time with my localhost sites to grab the images from the online production site. In your sub domain .htaccess file use the following.
<IfModule mod_rewrite.c>
# Attempt to load files from production if
# they're not in our dev version
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule wp-content/uploads/(.*) \
http://example.com/wp-content/uploads/$1 [NC,L]
</IfModule>
Related
I created a website few days back with a url http://abctest.com in wordpress. Now the website has been published to a domain http://www.bcdefg.com.
The server is same, I have not migrated the site, only the domain has been pointed to the same server. I have changed the wphome and wpsite url to respective domain.
What I want to achieve is to redirect all http://abctest.com or http://www.abctest.com requests to http://www.bcdefg.com.
I tried to use .htaccess redirection but that leads to Too many redirection error. Any solution ?
Below is my htaccess code.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
RewriteRule ^(.*)$ http://www.bcdefg.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Error is on your rewriteCond : your host is www.bcdef.com and not bcdef.com (www is important)
try replacing this
RewriteCond %{HTTP_HOST} !bcdefg.com$ [NC]
by this :
RewriteCond %{HTTP_HOST} !www.bcdefg.com$ [NC]
I got a issue with my htaccess-file. I learned a thing or two when it comes on rewriting through the htaccess-file, but this one is really keeping me awake. Hopefully one of you can help me solve with this matter. The situation is the following.
I want to redirect some specific WP blog posts (permanently) from a subdomain to some specific pages on this WP main domain subdirectory. I'm using a WP Multi subdomain website. Here's what I mean:
sub1.domain.com/postname
needs to be redirected to:
domain.com/sub1/pagename
I can't figure out how to get this done. Here's how my WP htaccess- file that's located on the root of this subdomain normally looks like:
#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
<Files 403.shtml>
order allow,deny
allow from all
</Files>
I hope someone can help me with this matter. It will truly help me. Thanks in forward!
Greets, Marc
Add the following HTTP_HOST rule just before your wordpress rules.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^postname/?$ http://domain.com/pagename [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
To redirect sub.domain.com to domain.com/subdir, you would use
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/subdir/$1 [R=301,L]
Having some trouble with this rewrite code. I want to add a few domains (all pointing to the same server) and make it so that they have a "hidden" URL prefix being sent to the server.
Example: You type in example-one.org/contact, the server looks at it as /one/contact/
Updated code based on #anubhava's answer
I still receive a 500 Internal Server Error when using this code. I put it through an htaccess tester and it looks like it should work.
Here is the full htaccess code, including WordPress' defaults, and without using example.org:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^discoverdowntownspringfield.org$ [NC]
RewriteRule ^((?!downtown-springfield/).*)$ /downtown-springfield/$1 [L,NC]
# 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
You can use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$ [NC]
RewriteRule ^((?!one/).*)$ /one/$1 [L,NC]
I'm organizing a client site into several subdomains. I've used the following to redirect all the posts on oldsite.com/blog-post-name to blog.oldsite.com/blog-post-name and it works like a charm. However, we want oldsite.com, oldsite.com/page1 and oldsite.com/page2 to remain as they are and NOT be redirected to the subdomain. I feel like I should be able to add an exception for the applicable pages - there are only 5 of them - but I can't figure out how that exception should read. For reference, oldsite.com is in the root directory and WordPress files are in oldsite/subdomain/subfolder.
oldsite.com htaccess:
RewriteEngine on
RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [R=301,L]
Update
Old code started breaking the theme CSS, and incidentally so does the new code. I'm thinking the negative condition is fighting with the basic WP htaccess. Here's what I have at the moment:
RewriteEngine on
RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^(repairs|contact)/?$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [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
Should I be adding the conditions within the WP set? Why did the code above work before (yes, with WP code)?
You can do:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(page1|page2)?$
RewriteRule ^(.*)$ http://blog.oldsite.com/$1 [R=301,L]
I know there are thousands of threads about this topic, but despite many hours of searc and try, I'm really unable to find a solution to my case. So I decided to ask for help.
This is my panorama
1) I have a domain www.mydomain.com with a Wordpress installation and Wildcard SSL certificate
As you probably know, Wordpress already writes some rules in .htaccess, these rules:
# 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>
2) now I need to put additional wordpress installations (no WPMU, but different installations) in other subdomains, pointing them to subdirectories that I would like to call "subdomain_NAMEOFTHESUBDOMAIN"
3) as far as I know, to extend the SSL certificate I cannot create subdomains via cPanel, but I have to do it with .htaccess rules
This is where I've been able to get:
1) I've created a wildcard CNAME *.mydomain.com
2) I've created a directory inside my public_html folder, called "subdomain_xxx"
3) I've added these rules (before the wordpress rules) to point the subdomain "xxx.mydomain.com" to the "subdomain_xxx" folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^subdomain_xxx/ - [L]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
RewriteRule ^(.*)$ subdomain_xxx/$1 [L]
</IfModule>
At first it seems to work:
if I go to mydomain.com I get the corretc "first level" wordpress www.mydomain.com
if I go to ANYTHING.mydomain.com I still get www.mydomain.com
if I go to xxx.mydomain.com I'm correctly pointed to the wordpress installation present in the "subdomain_xxx" directory
but there is a problem:
If I try to duplicate the procedure for any other htaccess-subdomain/subdirectory couple,
for example "subdomain_yyy" and "yyy.mydomain.com", duplicating the previous rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^subdomain_yyy/ - [L]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
RewriteRule ^(.*)$ subdomain_yyy/$1 [L]
</IfModule>
I keep being redirected to the first subdomain created: xxx.mydomain.com
To be very clear, this is my full .htaccess content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^subdomain_xxx/ - [L]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
RewriteRule ^(.*)$ subdomain_xxx/$1 [L]
RewriteRule ^subdomain_yyy/ - [L]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$
RewriteRule ^(.*)$ subdomain_yyy/$1 [L]
</IfModule>
# 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>
Surely there's a lot I do not understand about .htaccess (and regex), so I'm not only looking for a quick solution, but also some other infos to deepen my comprehension of this matter.
I hope someone will find the patience for that.
Thanks in advance
I just found out how to correctly do it
The rules I was using were all wrong.
this is the correct way
RewriteCond %{HTTP_HOST} ^xxx.mydomain.com$ [NC]
RewriteRule ^(.*)$ /subdomain_xxx/$1 [L]
If someone has a comment I will be glad to read it, thanks anyway