A
A
Andrey Kotosin2018-04-30 13:49:31
Apache HTTP Server
Andrey Kotosin, 2018-04-30 13:49:31

How to make redirect get page request to main page except some pages?

There is such a structure:
- Main (index.php)
- Login page (signin.php)
- Registration page (signup.php) - User
page (user.php)
- User admin panel (admin.php)
It works like this:
the main page is authorized and a session is created (if there is a session, it redirects to admin.php)
For each user, the user.php page takes the get parameter login. Thus, if you go to site.ru/user.php?login=user1, we will see user1's data from the database.
I want to convert the complex structure site.ru/user.php?login=user1 into site.ru/user1
I write the following in the .htaccess file:


RewriteEngine on
RewriteRule ^(.*)$ user.php?login=$1 [L]

But with this option, when I go to site.ru/user1, I get an error.
If I write:

RewriteEngine on
RewriteRule ^m/(.*)$ user.php?login=$1 [L]

and I turn to site.ru/m/user1, everything works as it should.
The question is how to redirect all site.ru/user.php?login=user1 requests to the main page, but at the same time exclude the registration, login and admin pages? Because if a person goes to site.ru/signin.php = as I understand it, it will be perceived as site.ru/user.php?login=signin.php
In general, I can’t figure it out. Can someone help?
And if possible, immediately with the option to exclude the .php extension in the address bar (whatever .php is shown)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-04-30
@webinar

https://habr.com/sandbox/10953/

V
Viktor Taran, 2018-04-30
@shambler81

GET is not part of the url and does not go to the rewrite rule.
To select it, we use a two-level construct
. Also, everything that is $1 from the conda will be %1
# 301 --- www.test.com/faq.html?faq=13&layout=bob => www.test2.com/faqs.html
If host such and such
AND if there is a get request such and such
AND THERE IS NO such and such a request Exception is !
RewriteCond %{QUERY_STRING} !(^|&)layout\=bob2($|&)
THEN execute such a rule
Such a construction is optional. (^|&)faq\=13($|&)
It can be reduced to faq \= 13, but the constitution itself chose the option with and without an upmersant.
Also pay attention to the end of the wheel itself, that at the end it stands ?in such a spelling will remove the get parameters altogether

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question