Redirect one image to webpage Issue - wordpress

I hope everyone is well.
I am having a few issues trying to redirect an image that was linked in error from an email to a html page.
For example the email points here - https://www.caravanguard.co.uk/news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg
But should point here - https://www.caravanguard.co.uk/news/make-mine-a-dealer-special-caravan-25644/
I have appplied the following to our .htaccess, but it does not appear to have worked. I have also done the same in the wordpress yoast plugin we use.
redirect 301 /news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg /news/make-mine-a-dealer-special-caravan-25644/
Any ideas?

With your shown samples, could you please try following. Please make sure to place these rules at top of your .htaccess file. Also please do clear your browser cache before testing any URLs.
RewriteEngine ON
RewriteRule ^news/wp-content/uploads/2021/03/Swift-Vogue-580-1\.jpeg/?$ /news/make-mine-a-dealer-special-caravan-25644/ [R=301,NC,L]

You can use a RewriteRule
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/news/wp-content/uploads/2021/03/Swift-Vogue-580-1.jpeg$
RewriteRule ^.+$ /news/make-mine-a-dealer-special-caravan-25644/ [R=301]
Make sure this rule is at the top of your htaccess or before your WordPress rules.

Had to remove the image from wordpress before it would allow the redirect to work. WP rules seem to have got in the way. The .htaccess rule I originally created then kicked in.
I tried the above comments prior to the deletion and they did not work. Cheers for your help both.

Related

Get data from one url by using custom url pattern wp

Can anybody suggest me this-
example.com/topic/a-1.html using this url i want to get data from
example.com/topic?page=a&number=1 in wp.
I tried wp rewrite functions but that could not helped me.
& I tried this too.
RewriteEngine On
RewriteRule ^([^/])/([^/]).html$ /topic?page=$1&num=$2 [L]
Thanks for your reply.
If you set permalinks in options, all links in your site will have the form site.com/page, but if you need delivery get parameter you can do it anyway, adding at the end of the get request site.com/page?id=1&page=2
Well finally i got this rule.
i was missing index.php thats why wp was redirecting to 404.
RewriteRule ^topic/([^/])/([^/])$ index.php/topic?page=$1&num=$2 [L]
Finally it worked for me. :)

Wordpress Home page URL changing to /?i=1 - issue

When I try to access my Wordpress website directly or from google, the Home page URL automatically adding /?i=1 and sometimes /?i=2 to the URL in the address bar.
I think it's a very simple to solve it, but I tried many things and didn't work.
So I wonder how can I solve this to be only the URL without /?i=1 or /?i=2 ?
/?i=1 or /?i=2 protects your website from bots and is mostly applied by free hosting services and if you use any .htaccess code to remove it than all ? parameters will removed and redirect you to homepage
Try resetting your wordpress permalink from admin end. If you don't know how to do that check this video. As this is not normal behavior of wordpress you can also check your .htaccess file.
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
Add this in htaccess

Redirect one specific Wordpress URL to another site for mobile users in htaccess

Need some syntax help if someone would be so kind. I have one page on my Wordpress site (http://www.thisweekonmv.com/vineyard-map) that I need to redirect to another website's URL for mobile users only. I would like to do this in .htaccess, but so far all of the solutions I've researched online haven't worked.
This is what I have that isn't working...I probably am close but something is definitely wrong?
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|operamobile|palmos|webos|googlebot-mobile" [nc]
rewriterule ^vineyard-map(.*)$ http://myatlascms.com/map/?id=938$1 [r=301,nc]
Refer this links
https://wordpress.org/support/topic/how-to-redirect-links-for-mobile-using-htaccess
Mobile Redirect using htaccess

RewriteRule gives 404

I have troubles with mod_rewrite.
I have wordpress site located in 'wp' directory. It is accessible as http://localhost/wp/
There is page http://localhost/wp/sample-page/ on the site.
I want to make this page open with url http://localhost/wp/sample-page-2/ without redirect.
Here is what in .htaccess file:
RewriteEngine On
RewriteBase /wp/
RewriteRule ^sample-page-2/$ sample-page/ [L]
But I'm getting 404 error.
Could somebody explain me what I'm doing wrong?
Thanks in advance.
UPD:
#soju: Well, "sample-page-2" - is just example
It is not a page/post in worpress sence.
Actually I tried to add one section to the url. E.g. http://localhost/wp/sample-page/section/. And this rule RewriteRule ^sample-page/section/$ sample-page/ [L] didn't work. Then I decided to "simpliyfy" url("sample-page-2" instead of "sample-page/section") - no success.
UPD2
BTW, redirect RewriteRule ^sample-page-2/$ sample-page/ [R=301,L] works
I suppose wordpress rewrite rules are after your own rule, so you should remove [L] option to let wordpress handle sample-page url
EDIT about UPD2 : Well, it works with a 301 redirection, but you said you don't want redirection ?
You can add a filter on rewrite_rules_array to make your own rewrite rule, take a look at example on codex : http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples

.htaccess 301 redirect from one subdirectory to another and preserve folder/directory structure

I've done a lot of searching on how to do this, but none of the solutions seem to be working with this specific problem of redirecting from one subdirectory to another while preserving the original folder/directory structure.
For example I would like to redirect all incoming deep links from:
example.com/post/123 to example.com/archive/post/123
Basically I just want to move my original Wordpress blog from the root directory to a subdirectory, but I have a few popular incoming links and I don't want them to break.
Would appreciate any help or if anyone has had similar experience moving blogs yet retaining their incoming links.
Thanks,
Josh
Please try this:
For each of your links write as follows in the .htaccess file
redirect 301 /OldSubdirectoy/old/old.htm http://www.domainname.com/NewSubdirectory/new/new/new.htm
Write in this structure for each of your popular links to keep SEO.
I figured this out a while ago properly and wrote an article about it on Medium:
Basically this is the code I needed in .htaccess in my root directory:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(p/.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(contact.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(about.*)$ http://phocks.org/historic/$1 [R=301,L]
RewriteRule ^(wp-content.*)$ http://phocks.org/historic/$1 [R=301,L]

Resources