i would like to make redirection 301 in htaccess for wordpress post to my home page
exemple work:
old post = https://www.example.com/keywordkeyworkeyword/
RedirectPermanent /keywordkeyworkeyword/ https://www.example.com
but for some articles I don't have the end of the url !
exemple no work:
old post = https://www.example.com/keywordkeyworkeywordKey...
RedirectPermanent /keywordkeyworkeywordKey(.*)$ https://www.example.com
The RedirectPermanent (mod_alias) directive does not take a regex, it uses simple prefix matching.
You need to use RewriteRule (mod_rewrite) near the top of your .htaccess, before the existing WordPress directives.
For example:
RewriteRule ^keywordkeyworkeywordKey https://www.example.com/ [QSD,R=301,L]
The above redirects any URL that starts /keywordkeyworkeywordKey to the homepage (root URL).
Test first with a 302 (temporary) redirect to avoid caching issues. You'll need to clear your browser cache before testing.
Related
I was using translatepress on my WordPress site so my site URLs were like example.com/en-ae/hair-transplant but now I have removed translatepress so now my URLs are like example.com/hair-transplant but I have submitted URLs for SEO with the en-ae slug. I want that if en-ae is present in any URL then it gets removed automatically and gets redirected to page without en-ae.
For example example.com/en-ae/hair-transplant redirects to example.com/hair-transplant.
You need the rewrite module of Apache: mod_rewrite.
Then in your htaccess this:
RewriteEngine on
RewriteRule ^en-ae/(.*)$ $1
To remove the /en-ae prefix from all requested URLs (to help preserve SEO), you would need to add the following near the top of the root .htaccess file, before the WordPress code block (ie. before the # BEGIN WordPress comment marker):
# Remove "/en-ae/" prefix from all requests
RewriteRule ^en-ae/(.*) /$1 [R=301,L]
You do not need to repeat the RewriteEngine directive, which already occurs later in the file (in the WordPress code block).
The R=301 flag triggers an external "permanent" redirect - without which the URL-prefix is not actually removed. However, you should first test with a 302 (temporary) redirect to avoid potential caching issues.
The slash prefix on the substitution string is necessary to avoid a malformed redirect, if the RewriteBase directive is omitted from the WordPress code block.
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.
How to Redirect
Old Link:
http://www.astrokapoor.com/products/gems/gemstones/ruby-manik-new-burmees/ (this is custom php/html site)
New Link- http://astrokapoor.com/en/ruby-manik-gemstone/ (this is wordpress site link)
I used below code but no success
RewriteRule ^/products/gems/gemstones/ruby-manik-new-burmees /en/ruby-manik-gemstone [L,R=301]
Let's assume both the source and the target reside in the different virtualhosts and that you are defining this in VirtualHost context. Let's also assume you are the admin of the site and you have no reason to define this in .htaccess context.
All you need is a Redirect directive in the source virtualhost:
Redirect /products/gems/gemstones/ruby-manik-new-burmees/ http://astrokapoor.com/en/ruby-manik-gemstone/
This will redirect /products/gems/gemstones/ruby-manik-new-burmees/ and all subpaths from it to the new url, such if someone requests:
Host: www.astrokapoor.com
GET /products/gems/gemstones/ruby-manik-new-burmees/something
they will get redirected to:
http://astrokapoor.com/en/ruby-manik-gemstone/something
Note: Redirect belongs to mod_alias. In such simple redirection cases you should avoid mod_rewrite. Use mod_rewrite only when you have no other choice.
Add this line in your old page html page.
<meta http-equiv="refresh" content="0; url=http://astrokapoor.com/en/ruby-manik-gemstone/" />
By using simple redirect plugin You can set your redirect links easily by define each URL to match each page.
Try to use this code in .htaccess file.
RewriteRule ^products/gems/gemstones/ruby-manik-new-burmees/$ http://astrokapoor.com/en/ruby-manik-gemstone/ [L]
RewriteRule ^sunsign/aquarius%4027.html/$ http://www.astrokapoor.com/en/Aquarius-sunsign/ [L]
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... :)