Htaccess Rewrite Advanced Rule for PHP

I currently have the following code to rewrite a friendly search URL to what PHP can handle, but there are a few problems.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*)/(.*) index.php?$1/$2

It overwrites domain.com/cat/mens/size/large/in domain.com/index.php?cat/mens/size/large/.


It would be ideal if I could rewrite it to something like this, using various numbers of helper directories, such as this, more PHP-friendly:

Perfect record: domain.com/index.php?cat=mens&size=large

Another example: domain.com/page/value/subpage/subvalue/something/true/

Rewrite to: domain.com/index.php?page=value&subpage=subvalue&something=true


There is also a way to rewrite: domain.com/search/?q=blah+blah

To: domain.com/index.php?search&q=blah+blah

+3
source share
1 answer

Try the following:

RewriteRule /page/(.*)/subpage/(.*)/something/(.*) index.php?page=$1&subpage=$2&something=$3

URL- , php (, , , ).

RewriteRule /search/?q=(.*) index.php?search&q=$1

:

RewriteRule /cat/(.*)/size/(.*)/?q=(.*)&abc=(.*) index.php?search&cat=$1&size=$2&q=$3&abc=$4

, RewriteRule - url, - , script. (somethingInHere) , , , $1, $2, $3 $4.

+2

Source: https://habr.com/ru/post/1734051/


All Articles