htaccess redirect wordpress folder change - wordpress

I currently have a url of http://example.com/wordpres/
I'm going to change this to http://example.com/w/
I currently get a lot of traffic from links already out on the web. How can I redirect everything that went to /wordpress to /w ?

RedirectMatch 301 ^wordpress(.*)$ /directory/path/to/w/$1
The above line should match every request coming to your domain with 'wordress' at the start and redirect it to /w/. The '301' tells the browser (and search engines) that the page(s) have moved permenantly. The $1 exists to redirect anything after /wordpress/ and append it to the redirected URL. So if I visit http://example.com/wordpress/this-post/ I would get redirected to http://example.com/w/this-post.

Add this rule to your .htaccess file:
RewriteEngine on
RewriteRule wordpress(.*)$ /w$1
If doesnt work.. let me know... :)

Related

Wordpress htaccess 301 redirect issue

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.

301 Redirect server IP to domain while keeping query string

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

"The page isn't redirecting properly" using redirect in .htaccess wordpress

I’m trying to rewrite the url from example.com/sub/sub1 to example.com/sub1 and remove the /sub/ path every time there is a /sub1 next to it.
My solution redirects to example.com/sub1 properly, but I am getting a loop redirect with the error message:
The page isn't redirecting properly.
My .htaccess file:
RedirectMatch 301 /sub(/.*)sub1 $1sub1
Any ideas on how to fix this?
Thanks, guys.
Edit: should be RedirectMatch 301 /sub(/.*)sub1 $1sub1
You should use redirects for specific pages, but if you want to redirect a whole subdirectory, you should be using rewrite rules instead. Using your example, you should have:
RewriteEngine on
RewriteRule ^/$/sub/sub1/(.*)$ /1sub1/$1 [R=301]

Redirect some .htm page to WordPress page without path and query string

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.

301 Redirect of folder to parent folder

I need to redirect /portfolio/year/ to /portfolio/.
The issue with the 301 I have written currently (redirect 301 /portfolio/year http://example.com/portfolio/) is that it redirects when someone attempts to access /portfolio/year/2000 or any of the other pages inside /year/.
Is there a way I can do this redirect? I need to keep bots and people from accessing the blank /portfolio/year/ page without breaking the rest of the internal pages.
You don't have to use PHP for this. Just replace your old RewriteRule with this one: RewriteRule ^portfolio/year/?$ portfolio [R=301] The $ at the end of the url makes sure that there are no more characters after portfolio/year/ or portfolio/year

Resources