M
M
Mikhail2015-10-04 23:40:56
Apache HTTP Server
Mikhail, 2015-10-04 23:40:56

How to convert links from GET to CNC?

Hello. There is a simple CNC through .htaccess.
Yes, I know that CNC needs to be done through PHP, i.e. in .htaccess redirect to the entry file (index.php) and parse the url there (something like this). But so far it has been done.
The actual code is below:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
</IfModule>

The CNC works, but the problem is that the link, let's say contacts, is available both through the CNC (/contacts) and through the usual GET (/?page=contacts).
Question: How to make a redirect from GET to CNC if the user logged in via GET ? Those. we go to site.ru/?page=contacts, and we are redirected to site.ru/contacts
I tried this, but it does not work:
RewriteCond %{QUERY_STRING} ^/index.php?page=(.*)$
RewriteRule ^/index.php?page=(.*)$ /$1 [L,R=301]

Thank you for your time!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Defman21, 2015-10-05
@Defman21

The dot is a special character.
The question mark is a special character.
In regular seasons, they need to be screened.
Your expression matches a string like /indexfphpage=123 or /indexsphppage=123 (i.e. after index there is 1 any character except for a line break (\n), in php the last p is optional (because of ?))
Correct regular expression - ^/index\.php\?page=(.*)$
But I don't understand the meaning of such a redirect =\

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question