P
P
prrrrrrr2020-02-27 12:48:20
htaccess
prrrrrrr, 2020-02-27 12:48:20

How to replace "somepage.php?id=1" with "somepage/1", etc.?

Tell me how to replace "somepage.php? id=1" with "somepage/1" and other pages similarly?

I found a solution where .php is truncated , but how to make a route from id=1 to /1?

# Запускаем движок замены
RewriteEngine on

 # Если запрашиваемый объект не папка
RewriteCond %{REQUEST_FILENAME} !-d

 # если запрашиваемый объект с дописанным расширением php - файл
RewriteCond %{REQUEST_FILENAME}\.php -f

 # делаем замену с дописыванием .php
RewriteRule ^(.*)$ $1.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-02-27
@prrrrrrr

RewriteEngine on

RewriteCond %{THE_REQUEST} "^GET /(somepage)\.php(?:.*?[?&]id=(\d+)|)"
RewriteRule ^ /%1/%2? [R=301,L]

RewriteRule ^(somepage)/(\d+)$ /$1.php?id=$2 [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question