I have one problem about the redirecting I want to make redirect to example.com/12321.html to example.com?p=12321.
I was user before url typle like first number things after this i change my system to seo url with content name to url. Now i guest best system to redirect to ?p=
What I Try
First i try to change that on .htaccess not working i use this code
RewriteEngine On
RewriteRule "^([0-9]+)+[^.html]" "https://www.example.com?p=$1"
Than I thing to make that with nginx write this code on nginx server block
rewrite ^([0-9]+)+[^.html] https://www.example.com/$1 redirect;
I don’t understant that is why not working, I check it already on https://regex101.com/r/pimHGN/1 showing working there.
2
Answers
Ok, as a quick check, you could try a regex like the following for Apache:
And something like this for Nginx:
This should match any page composed of digits
0-9
and.html
.The rule you posted wouldn’t match on the
.html
part, which might be why it wasn’t working.Not too clear what you’re trying to do, however, unless you have a
rewrite
rule that’d be removing/
from$uri
first, your rule ofrewrite ^([0-9]+)+[^.html] https://www.example.com/$1 redirect;
would never match, because it is impossible for$uri
to not start with/
, hence,^([0-9]+)
would never catch anything. (Additionally,[^.html]
looks suspect as well — I have a feeling that it wouldn’t do what you expect it might.)The correct way may be:
However, as per nginx redirect loop, remove index.php from url and related, the following “loop” might be what you actually want:
The above code would ensure that the
/?p=
style is only used internally within nginx and the backend, whereas externally, everything always gets redirected to, and served from, the.html
-style pages.