/ / htaccess reindirizza con ID univoco a title - .htaccess

htaccess reindirizza con id univoco a title - .htaccess

Ho URL in questo modo:

http://www.example.com/en/product.php?id=23&t=page-title-here

Voglio cambiare URL per qualcosa di simile a questo:

http://www.example.com/en/product23/page-title-here/

risposte:

1 per risposta № 1

Inserisci quanto segue nel tuo /.htaccess file:

RewriteEngine on

# Step 1: Redirect file-based URIs to new "pretty permalinks" and prevent looping
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^id=(d+)&t=([^/]+)$ [NC]
RewriteRule ^(en/product).php$ /$1%1/%2? [R=302,NE,L]

# Step 2: Rewrite above permalink to file-based URI
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en/product)(d+)/([^/]+)/?$ /$1.php?id=$2&t=$3 [L,QSA]

Aggiornare: Se vuoi abbinare più lingue (per il tuo commento qui sotto), puoi usare un gruppo non di cattura che controlla esattamente due caratteri invece di en:

# Use this rule in step 1 above
RewriteRule ^((?:[a-z]{2})/product).php$ /$1%1/%2? [R=302,NE,L]
# Use this rule in step 2 above
RewriteRule ^((?:[a-z]{2})/product)(d+)/([^/]+)/?$ /$1.php?id=$2&t=$3 [L,QSA]