A
A
Alexey Melikov2019-10-23 10:53:15
Apache HTTP Server
Alexey Melikov, 2019-10-23 10:53:15

How to make an htaccess redirect when a specific url is requested?

Hello. Tell me how to make a redirect to the index.php script when requesting such URLs
domen.ru/page
domen.ru/page?p=123
domen.ru/page/1asd
domen.ru/page/1asd?p=123
Parameters (? p in the example) should also be passed to index.php
I tried this, but for some reason it does not work

RewriteCond %{REQUEST_URI} !^/page(/|$)
RewriteRule ^([^/]*)(/?)+$ /index.php?url=$1 [L]

If you create a page folder and put an htaccess script with this content in
RewriteRule ^([^/]*)(/?)+$ /index.php?url=$1
it, then everything works correctly. You need the same thing, but only that the htaccess script is in the root of the site. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-10-23
@AlekseyMelikov

RewriteRule ^page(?:/([^/]*))?$ /index.php?url=$1 [QSA,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question