rutas htaccess example enrutador crear con amigables php apache .htaccess pagination

php - example - .htaccess cambiar una ruta a una cadena de consulta



rutas con htaccess (1)

Tengo archivos en example.com/

contact.php recent.php videos.php watch.php

example.com/page/ > /page/ no es una carpeta. pero quiero trabajar otras carpetas

contact.php (sin paginación)

example.com/page/contact

recent.php ( pagination > recent.php?page=2 )

example.com/page/recent example.com/page/recent?page=2

watch.php ( no pagination > watch.php?title=drama-name )

example.com/page/watch/drama-name

videos.php ( pagination with get name > videos.php?name=drama-name&page=2 )

example.com/page/videos/drama-name example.com/page/videos/drama-name?page=2

Aquí están mis códigos htaccess completos (example.com/.htaccess)

RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^www/. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L] RewriteRule ^page/playlist$ /playlist.php [L] RewriteRule ^page/submit$ /submit.php [L] RewriteRule ^page/contact$ /contact.php [L] RewriteRule ^page/search$ /search.php [L] RewriteRule ^page/recent$ /recent.php [L] RewriteRule ^page/watch/([^/]+)? /watch.php?title=$1 RewriteRule ^page/videos/([^/]+)? /videos.php?name=$1

Pero no funciona en /page/videos/drama-name?page=2 ¿cómo solucionarlo? tiene otro problema?


Puede combinar expresiones regulares y acortar sus reglas en su .htaccess con la bandera de QSA :

RewriteEngine on RewriteBase / # add www in host name RewriteCond %{HTTP_HOST} !^www/. [NC] RewriteRule ^(.*?)/?$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L] # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ /$1 [NE,R=301,L] RewriteRule ^page/(submit|contact|search|recent|playlist)/?$ $1.php [L,NC] RewriteRule ^page/(videos|watch)/([^/]+)/?$ $1.php?title=$2 [L,QSA,NC]