0

I have links on my Wordpress website with %ef%bb%bf at the end of URLs, I changed them directly on database, but know I have to redirect the old ones to the new version.

I tried via .htaccess, but it doesn't work :

Redirect 301 /category/old-uri%ef%bb%bf/ https://example.com/category/new-uri

I tried different variants too, but nothing works.

Do you have ideas ?

Thanks

gael
  • 1,314
  • 2
  • 12
  • 20
mopinto
  • 1
  • 2
  • What does happen when you request your old link with this `.htaccess` ? Make sure that any `.htaccess` file installed in the same directory is working. – Accountant م Apr 04 '20 at 07:38
  • Nothing happen. The old page with the old url appears. The redirection doesn't work. I tried with the part without %ef%bb%bf : Redirect 301 /category/ https://mywebsite.com/category/new-uri and this goes right. – mopinto Apr 04 '20 at 08:16
  • OK, then check [this question](https://stackoverflow.com/questions/13720650/htaccess-url-encoded-string-not-passing-to-page-correctly) and [this](https://serverfault.com/questions/925925/redirect-to-encoded-url-parameter-using-mod-rewrite-in-htaccess). – Accountant م Apr 04 '20 at 08:21
  • the last characters are HTML entities, when I used the HTML table https://krypted.com/utilities/html-encoding-reference/ i got these characters :  – userX Apr 04 '20 at 09:01
  • I tried the RewriteRule directive instead Redirect 301, but still the redirection doesn't go well and I get a 404. My code : RewriteRule /category/old-uri%ef%bb%bf/ example.com/category/new-uri [B, R=301] – mopinto Apr 05 '20 at 04:36

1 Answers1

0

You have to add the B rewrite flag. This flag tells mod_rewrite to escape backreferences as described in this answer in @Accountant link.

Redirect 301 /category/old-uri%ef%bb%bf/ https://example.com/category/new-uri [B]

Will escape the special character and lead https://example.com/category/old-uri%ef%bb%bf/ to The new url https://example.com/category/new-uri

gael
  • 1,314
  • 2
  • 12
  • 20
  • It added the [B at the end of the line, it ]gives me an "Internal Server Error" for the entire website. – mopinto Apr 04 '20 at 23:34
  • Hi Gael, I just used the RewriteRule directive instead Redirect 301. I no longer get the Internal Server Error, but still the redirection doesn't go well and I get a 404. My code : RewriteRule /category/old-uri%ef%bb%bf/ https://example.com/category/new-uri [B, R=301] – mopinto Apr 05 '20 at 00:16
  • do you have other rules in your htaccess that could cause the Internal server error? The code in my answer works without error on my test website. – gael Apr 05 '20 at 08:04
  • That code is encapsulated in a But before that one, yes there is other rules, in other like this one : – mopinto Apr 05 '20 at 15:46
  • # BEGIN WordPress # Les directives (lignes) entre 'BEGIN WordPress' et 'END WordPress' sont # généré dynamiquement, et ne doivent uniquement être modifiées via les filtres WordPress. # Toute modification des directives entre ces marqueurs sera outrepassée. RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress – mopinto Apr 05 '20 at 15:46
  • There is other rules before that one too, like an or an , a , a Those are generated by Wordpress. – mopinto Apr 05 '20 at 15:49
  • So try to put the code in my answer at the very top of your `.htaccess` file. – gael Apr 05 '20 at 17:42
  • ça à marché ? :) – gael Apr 07 '20 at 07:49