Rewriting URL still redirects to old URL - wordpress

I am trying to access
https://www.onlybrighton.com/optin-ninja/onlybrightona/
using
https://www.onlybrighton.com/jani
but it doesn't seem to be working right and it's redirecting me to
/onlybrightona/
URL when I enter
/jani
URL in browser
I am using follwing rule:
RewriteRule ^jani$ /optin-ninja/onlybrightona/ [QSA,L]
Apologies for being so blunt but I really am new into this.
Edit: in a nutshell my problem is .htaccess rule redirecting, but not rewriting

Can you please try it :
RewriteRule ^jani/?$ https://www.onlybrighton.com/optin-ninja/onlybrightona/ [R=301,NC,L]
Please try above code and let me know.

Related

.htaccess regex beginner redirection problem

I'm a beginner in redirecting with htaccess. I wanted to do a small redirect, but am already stuck.
My first redirect was:
RewriteRule ^/project/(.*) /search/?type=details&projectid=$1 [R=301,L]
Which works fine. The problem is, that if the link gets shared on facebook, the outbound link of facebook is added with a ?fbclid=XXX. So my links get turned into:
/search/?type=details&projectid=1?fbclid=XXX
So now I somehow have to find the "?fbclid=XXX" (in case there is one) and stick it behind a &. For now I have:
RewriteRule ^/project/([^/]*)/?(.*)$ /search/?type=details&projectid=$1&$2 [R=301,L]
But this only works if there is a / inbetween the projectid and ?fbclid.
Can anyone give me a clue, what I'm missing?
thank you very much.

Redirect one image to webpage Issue

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.

URL rewriting with WordPress

I have WordPress running on Apache, I have some URL like this one:
https://www.mywebsite.com/fr/?type=Manager
And I want it to be :
https://www.mywebsite.com/fr/manager/
I tried different things such as:
RewriteRule ^?type=Manager$ manager/
but it's not working. With this one for example I'm getting a 500 error, and sometimes it just does nothing. I don't know if it's my htaccess config, or because it's WordPress or because I'm stupid.
Use this rule in your .htaccess instead:
RewriteRule ^fr/([^/]*)$ /fr/?type=$1 [L]
Make sure you clear your cache before testing this.

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. :)

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

Resources