Simple .htaccess rule to redirect subfolder - wordpress

How do i edit the .htaccess file to redirect all links in a subdirectory to another subdirectory
inactive url
http://example.com/dir/archive/AnythingHere
redirect location
http://example.com/dir/new/

You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^dir/archive/(.*)$ /dir/new/$1 [L,NC,NE,R=302]
Make sure to place this rule as very first rule in your WP .htaccess file

Related

Replace index.php with htaccess rewrite

I'm using wordpress and it run will index.php on root. How do I make one of my folder, says its name is script to run instead of index.php using htaccess rewrite? Redirecting is one of the way but that's not what I want, because it can't retain the URL. I want example.com to serve the content of example.com/script without changing the url.
You can use DirectoryIndex
DirectoryIndex script
This will internally map your homepage to /script
another solution is mod-rewrite
Put the following rule above your existing rules after the RewriteEngine directive :
RewriteRule ^$ /script [L]

WordPress > htaccess > redirect directory and all its sub-directories to one directory

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

.htaccess redirect in wordpress

I would like users that go to the website 'http://kevingstongramado.p.ht/',
to be redirected to 'http://kevingstongramado.p.ht/catalogo/'. Which is in fact a wordpress website.
I´ve tried this:
Redirect 301 /http://kevingstongramado.p.ht/ http://kevingstongramado.p.ht/catalogo/
Putting the .htaccess inside the root directory of the website. Not the root directory of the folder which contains the wordpress.
Doesn´t work.
"catalogo" is the folder which contains the 'index.php' that opens the wordpress website.
Anyone?
Use RedirectMatch
If I am not wrong, you should use the relative path.
Create the index file index.htm in your root folder. Then,
RedirectMatch 301 /index.htm /catalogo//$1
.htaccess files are calculated by searching and interpreting the configuration for every .htaccess file in every directory in the path under the document root.
You want something along the lines of
RewriteCond ${REQUEST_URI} !^/catalogo/ [NC]
RewriteRule ^(.*)$ /catalogo/$1 [L]
This makes the rule conditional. It will only execute the rule if /catalogo/ is not present in the request uri. And the actual rule says to take everything and put /catalogo/ in front of it... and that it is the last rule to be executed in the file. This file will be reprocessed when it goes to the /catalogo/ directory.

Redirect Subdirectory to root domain

I want to redirect an entire subdirectory on my site i.e. http://www.mydomain.com/subdirectory to the root domain of my site http://www.mydomain.com can someone please tell my how to do so via .htaccess?
I had tried with Cpanel and enabled wildcard redirect but, sadly it's not working!
The subdirectory is actually a separate WordPress installation.
Thanks
Look into this: 301 redirection
Put the following .htaccess file into the root directory:
Redirect /subdirectory http://www.example.com
(requires mod_alias to be loaded) or use mod_redirect and put the .htaccess file into the subdirectory:
RewriteEngine On
RewriteRule (.*) http://www.example.com/$1
See: http://httpd.apache.org/docs/current/rewrite/ for mod_rewrite documentation.

.htaccess Subfolder Redirect

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

Resources