简体   繁体   中英

htaccess modify rule to match with or without htaccess

RewriteRule ^section-([^.]+)/([^.]+)-C([^.]+)/?$ /index.php?section=$1&dossier=$2&catid=$3 [L,QSA,NC]
RewriteRule ^section-([^.]+)/?$ /index.php?section=$1 [L,QSA,NC]
RewriteRule ^([^.]+)-C([0-9]+)/?$ /index.php?section=tshirt&dossier=$1&catid=$2 [L,QSA,NC]

This rule works almost perfectly, except it doesn't match url with index.php at the end. So something like this

https://www.domain.com/test-C118036/index.php?p=2&couleur=120

will result in 404 error, but this one will work:

https://www.domain.com/test-C118036/?p=2&couleur=120

You can add a rule before these rules to strip /index.php from URI:

DirectoryIndex index.php
RewriteEngine On

RewriteRule ^(.+)/index\.php$ /$1 [NC]

RewriteRule ^section-([^.]+)/([^.]+)-C([^.]+)/?$ index.php?section=$1&dossier=$2&catid=$3 [L,QSA,NC]
RewriteRule ^section-([^.]+)/?$ index.php?section=$1 [L,QSA,NC]
RewriteRule ^([^.]+)-C([0-9]+)/?$ index.php?section=tshirt&dossier=$1&catid=$2 [L,QSA,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM