N
N
nadirq2014-06-03 11:43:21
PHP
nadirq, 2014-06-03 11:43:21

301 redirect and circular addressing - how to solve the problem?

This is how it goes.
On the site, all pages are connected to index.php
parameters are passed via GET. That is www.site.ru/index.php?page=news .
The task was to make a CNC like www.site.ru/news/
I did this by adding the line to .htaccess:
RewriteRule ^(record|feedback|personal|licenses|work)/?$ index.php?page=$1 [L,NC]

But now you still need to make a 301 redirect from the old addresses to the new ones. That is, if I write www.site.ru/index.php?page=news in the address bar, then it redirects to www.site.ru/news/
BUT
Since www.site.ru/index.php?page=news and www.site.ru/news/is the same page, then it turns out that the page will be redirected to itself.
What needs to be done so that when requesting www.site.ru/index.php?page=news it goes to www.site.ru/news/
How can this be organized? Well, my head is spinning.
I didn’t find an answer to the question anywhere, and I hope for an adequate and intelligent Habr community.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
ShamblerR, 2015-06-30
@ShamblerR

Exclude with ! pages for which the redirect will not work, in this example I excluded the index.php file if you need a more complex url construction, then RewriteCond %{REQUEST_URI} !

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !index.php$
RewriteRule ^(record|feedback|personal|licenses|work)/?$ index.php?page=$1 [L,NC]

Y
Yuri Morozov, 2014-06-03
@metamorph

Nifiga did not understand.
Put a regular redirect on the old addresses, roughly speaking, if the user opens /index.php?page=news, then he will be redirected (with a change in the address in the address bar) to /news
Requests like /news are processed through the entry point (index.php), without redirect.
In what place here can there be a cyclic redirection?

I
iDennis, 2014-06-03
@iDennis

can do everything from php? For example check $_SERVER['REQUEST_URI'] and do a redirect. or read here .

I
IFK, 2014-06-03
@IFK

Do something like this:

$ref=$_SERVER['QUERY_STRING'];
if ($ref!='') $ref='?'.$ref;
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://newdomain.ru/'.$ref);
exit();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question