S
S
Slash2017-10-25 09:31:44
URL Handling
Slash, 2017-10-25 09:31:44

Remove part of URL?

Hello!
You need to remove this part of the index.php?do=/ from the url .
The page is available at two addresses, for example:
/forum/thread/1068/
/index.php?do=/forum/thread/1068/
Or:
/blog/18/
/index.php?do=/blog/18/
PS defines duplicates... Tell me how to properly redirect to a url where there is no index.php?do=/ .
Thank you.
Tried like this and like this:
RewriteRule ^index.php?do=(.*)$ $1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=/$1

Doesn't want to work...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slash, 2017-10-25
@Slash-Zn

It doesn’t work for me to remove part of the url on Apache, I did it on php:

$request = $_SERVER['REQUEST_URI'];

    if (stristr($request, 'index.php?do=/') !== false)
    {
      $url = str_replace('index.php?do=/', '', $request);

      header('Location: ' . $url, true, 301);
      exit;
    }

V
Viktor Taran, 2017-10-25
@shambler81

RewriteCond %{QUERY_STRING} (^|&)do\=(.+)($|&)
#Если    гет запрос содержит do= и более 1 знака, так же по краям  (^|&)($|&)  - это поскольку гет может быть вторым а следовательно начинаться с &
RewriteRule ^(.*) /%2 [L,R=301]
#то перенаправить на %2 -  это аналог $2 только из конда ( вторая скобка из конда)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question