перезапись URL с помощью QUERY_STRING - PullRequest
0 голосов
/ 03 мая 2019

Я хотел бы переписать http://example.com/test/index.php?id=123 в http://example.com/test/item/123/ и http://example.com/test/index.php?id=123 перенаправить на дружественный человеку URL.
Я не знаю, что не так в моем htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On    
RewriteBase /test/

RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]

1 Ответ

1 голос
/ 03 мая 2019

Вы можете использовать следующую RewriteRule в вашем /test/.htaccess файле

Options +FollowSymLinks -MultiViews
RewriteEngine on

#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...