Questions & Answers

how to redirect a dynamic url?

I have a URL

=> abcderf <= is dynamic, it is never the same value.

I would like to redirect with .htacess from :


How to do ?

My attempt:

RewriteCond %{REQUEST_URI} (\page\.[a-zA-Z0-9])$
RewriteRule ^(.+)/$ [R=301,L]
2023-01-24 23:01:14
/abcderf / [a-zA-Z0-9] - Do you need to be specific with what comes after /page/? Or is it OK to match any URL that simply starts with /page/? Your example URL does not end with a slash, except that your RewriteRule specifically matches only URLs that do end with a slash?
Answers(2) :

You don't need any conditions, one single line should work:

RewriteRule ^page/(.*) /page/ [R=301,NC,L]

or as MrWhite mentioned if you don't need to know what was in the URL

RewriteRule ^page/. /page/ [R=301,NC,L]

NC = no case L = Last (don't run anything after) R=301 = 301 redirect

2023-01-24 23:01:14
There's no second (or trailing) slash in the example URL in the question. This could perhaps be simplified to just ^page/. (no need for the capturing subgroup).

Good morning,

It doesn't work. Do you have an idea ?

I am using Wordpress CMS.

enter image description here

enter image description here

2023-01-24 23:01:14
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review