I recently moved my WordPress website to a subfolder. I want to add a redirect in the .htaccess file so that the links to images I've uploaded originally to ~/wp-content/uploads/ will pass to ~/blog/wp-content/uploads. The .htaccess file must remain in the root folder for WordPress to read it properly. This is what I tried
Redirect /wp-content/uploads/ /blog/wp-content/uploads
That worked great, except I host other domains on this account, and all of the other domain's upload folders were being redirected in a similar manner.
Is there a way to restrict this redirect to just one domain? So that example.com/wp-content/uploads redirects to example.com/blog/wp-content/uploads, but another.com/wp-content/uploads does not?
Thanks everyone!
Assuming you want a 301 redirect, using this RewriteEngine example should work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteRule ^wp-content/uploads/(.*)$ http://www.example.com/blog/wp-content/uploads/$1 [R=301,L]
You should place the Redirect inside the <VirtualHost> definition for example.com in the httpd.conf (or equivalent) instead of .htaccess
on a sidenote, Redirectsays temporary / 302 by default, so it is nicer to use
Redirect permanent /wp-content/uploads/ /blog/wp-content/uploads instead
Related
Why I can't redirect subdomain from htaccess while using CloudFlare SSL?
PS I don't know if I can paste URL here so I won't paste it to avoid removal of the question.
I'm getting this problem in Chrome (but it doesn't work in Firefox either)
error
I know there are fixes on the internet for this error but none worked for me. Is it because I have root domain connected to CloudFlare (also affects subdomains)?
What I did is:
1. created a subdomain in hosting and set its file directory.
2. in that file directory made .htaccess file.
3. inside the file
Redirect 301 / https://rootdomain/firstfolder
but it falls into redirects loop :(
With my .htaccess code, I check if the domain has the www. dub on the domain, then I redirect it to the subdomain without the www. dub on it. Also, because I don't think you want to change it, I place a 301 Redirect on it also.
I forgot to mention, usually people do not use the www. on the subdomain also, so I am guessing that you don't want people to use it either.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "http\:\/\/sundomain\.domain\.com\/" [R=301,L]
For specific url : put below code in your subdomain.domain.com's .htacess
Redirect 301 /blue-car/ http://www.example.com/cars/red-car
I have a WordPress site stored and served from in a subdirectory: eg https://example.com/en/
We now need to serve it from the root of a new domain eg https://exampletwo.com/, ideally without moving the installation. The domain is already setup as a parked domain on the cpanel and serves the WordPress site correctly.
Changing the siteurl and homeurl automatically redirects https://example.com/en/ to the new location https://exampletwo.com to the correct location and works fine as expected.
The problem is with external links:
https://example.com/en/ now returns a WordPress 404 error. Setting up a page called /en/ putting a redirect to https://exampletwo.com/ works fine. A bit clumsy but works for now.
However they also used to have pages like
https://example.com/en/contact and these return server 404 errors outside of WordPress, i.e.:
The requested URL /index.php was not found on this server.
I'm trying to avoid physically moving the WordPress installation. I'm guessing that when making a request to the /en/ directory, it's actually looking for resources in the /en/en/ directory.
Is it possible to accomplish this using .htaccess / WordPress or some other method or am I best to move the installation to a new location
Thanks for any thoughts
This would be the .htaccess code you'd need in the example.com/en/ folder to redirect everything to the exampletwo.com domain. Again, it would go in the /en/ folder and not the root folder for example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://exampletwo.com/$1 [L,R=301,NC]
I didn't quite find what I need despite I'm sure it is asked before..
I need to rewrite index.html to a subdirectory but allow index.php to be visited.
I have a Wordpress installe in the root, but as long it is in dev I would like it to be visited if addressed directly with exact path and all visitors writing the domain only to be redirected. Thought and tried todo this with .htaccess
Redirect /index.html http://www.example.com/home
But this redirects also index.php to the subdirectory.
I also tried adding
remove_filter('template_redirect', 'redirect_canonical');
To the functions.php
What next?
Put the following code at root .htaccess file :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*) /home/$1 [L,R=302]
the above code will redirect any request to /home/ directory including main domain and excluded only the index.php
for example if request site.com/page it will go to site.com/home/page
if you request site.com it will direct you to site.com/home/
but if you request site.com/index.php it will go to site.com/index.php
Is it possible to redirect a directory and all its sub-directories to another location with a single redirect rule within wordpress´ htaccess file?
e.g.
http://example.com/old
http://example.com/old/foo
http://example.com/old/foo/bar
move them all to
http://example.com/new
--
when I try this
RedirectMatch 301 ^/old/(.*)$ /new/
while pointing to
http://example.com/old/foo/bar
it ends up with
http://example.com/new/bar
You can put this rule in your htaccess (before Wordpress' main rule, after RewriteEngine On line)
RewriteRule ^old(/.*)?$ /new [R=301,L]
Note: you may have to clear your browser cache since your old rule is stored into it
I have a wordpress subdomain that I need to redirect to the main domain and I would like the subdomain masked. How do I do this? I tried the wordpress redirection plugin but that didn't work.
http://2014.mydomain.com to go to http://mydomain.com
Also upon redirection I do not want my subdomain name to appear.
Thank you!
Try adding this to the htaccess file in your document root (the one for 2014.mydomain.com). Make sure to add the rules before any wordpress related rules that's already in the htaccess file:
RewriteCond %{HTTP_HOST} ^2014\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R]