问题
I have a problem with URL rewriting. I have written the following rule in my .htaccess file
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
It gives me URLs like that : http://localhost/actuco/c-628Y8x-france/ (featuring the ID of the category, and its slug). This URL works perfectly.
But, when I type this URL : http://localhost/actuco/c-xpS3cc-amerique-du-nord/ it doesn't works anymore. The cause of the problem must be the fact that the latter slug contains several hyphens (amerique-du-nord) whereas the first one (france) contains no hyphens at all (I tried with all my categories with slugs including multiple hyphens).
Does anyone know how to solve this please ?
Here is my complete .htaccess code
Options +FollowSymlinks
RewriteEngine On
RewriteBase /actuco/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} /+[^\.]+$
#RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
#RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2
RewriteRule ^bio$ o.php [L]
Thanks in advance !
回答1:
You can try:
RewriteRule ^c\-([\w]+)\-([\w-]+)\/$ cat.php?id=$1&slug=$2
来源:https://stackoverflow.com/questions/53288730/multiple-hyphen-handling-in-htaccess-url-rewriting