A
A
Alexey Sklyarov2018-02-17 17:03:12
htaccess
Alexey Sklyarov, 2018-02-17 17:03:12

How to rewrite index.php?param=name to /param/name?

Actually the question itself is in the top. I'm trying to do this:

All htaccess
RewriteEngine On
# RewriteCond %{ENV:HTTPS} !on
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} index\.php
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

RewriteRule ^coin/(.+)$ /index.php?coin=$1 [L]


The last line I try to implement index.php?coin=Name in site.ru/coin/name, but site.ru/?coin=name comes out instead, it seems to me that this is due to other rules in the document, but it is correct to solve this problem I don't get out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-02-28
@shambler81

GET is not part of the url, so it stands out separately.

# 301 --- http://www.mydefile.ru/lookbook/?type=Рекламные+кампании&PAGEN_1=2 => http://www.mydefile.ru/news/campaigns/
RewriteCond %{QUERY_STRING} (^|&)type=Рекламные\+кампании($|&)
RewriteCond %{QUERY_STRING} (^|&)PAGEN_1=2($|&)
RewriteRule ^lookbook/$ /news/campaigns/? [L,R=301]

All that remains for you is to collect a group in the get parameter
RewriteCond %{QUERY_STRING} (^|&)(coin=Name)($|&)
RewriteRule ^.*$ %2? [L,R=301]

Where %2is the clear group from RewriteCond - analogue of $2 if it was a wheel
Also in the rule I showed that the parameter can be anywhere how to start with ? so with &
If without it, then it can be even simpler
WELL and of course it will already be %1
PLEASE NOTE THAT
there is a question mark at the end, it will remove all get parameters from the path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question