I need/want to redirect 404 from a specific sub-folder to another page. I am using WordPress. I suspect this would likely be done using .htaccess. I am really struggling with the code. For example...
I would like www.mydomain.com/knowledge-base/url-does-not-exist/ to redirect to www.mydomain.com/knowledge-base/.
Any 404 that is not associated with the sub-folder "knowledge-base" should use the default 404 page set out in WordPress.
I should note that the sub-folder "knowledge-bsae" doesn't actually exist - it is virtual.
Can someone help me with the code?
you could try to insert RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L] to .htaccess , make sure there's RewriteEngine On, and paste the code below it.
this reference might help you redirect directory to another
301 is permanent and 302 is temporary for redirect.
another option is, ( i haven't tried this yet ) but you could add another .htaccess file to your subfolder, then ErrorDocument 404 /path/to/yourcustompage .
good luck
Related
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.
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.
I only have one 404 left and have no idea how to fix it. So I need to redirect that single page to the home page.
I need http://www.name.co.uk/blog/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif to redirect to the homepage within the .htaccess file.
Many thanks
Sorted it.
Redirect 301 /blog/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif http://www.name.co.uk/
Just add the following line to your .htaccess file :
ErrorDocument 404 /index.php
It's work for me.
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
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... :)