Skip to content

Instantly share code, notes, and snippets.

@HueJack
Last active July 5, 2019 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HueJack/b743a6ff9b44abd9a84edd6c3b016961 to your computer and use it in GitHub Desktop.
Save HueJack/b743a6ff9b44abd9a84edd6c3b016961 to your computer and use it in GitHub Desktop.
Часть пути переносим в GET параметр
К примеру! У нас есть сайт с одним набором файлов, нужно лишь фильтровать по разным городам.
Чтобы не изменять файловую структуру сделаем следующее:
1. Добавим ссылки формата:
- https://sitename.ru/moskow-city/vacancy/
- https://sitename.ru/spb-city/vacancy/
2. В .htaccess пропишем RewriteRule ^([^/]+)-city\/([^/]+)\/.* /$2/?city-code=$1 [NC,L]
3. В файле по адресу /vacancy/index.php работаем с get параметром city-code, в нем будет содержаться moskow или spb
Если хочется, чтобы в $_GET массив попали еще и QUERY_STRING, то добавляем
RewriteCond %{query_string} (.*)
RewriteRule ^([^\/]+)-city\/([^\/]+)\/?(.*) /$2/?city-code=$1&%1 [NC,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment