0
我想匹配以破折號和一組號碼(或只是一個數)結尾的URL,但不工作:的.htaccess MOD-重寫URL以「-XXXX」(破折號,數字)結束
例子:domain.com/my-product-36-inches-long-135355
# rewrite urls
Options +SymLinksIfOwnerMatch +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase/
# product
RewriteRule ^shop/-([0-9,]+)/?$ product.php?url_key=$1 [NC,L]
# category
RewriteRule ^shop/([^/.]+)$ category.php?url_key=$1 [NC,L]
# sub category
RewriteRule ^shop/([^/.]+)/([^/.]+)$ subcategory.php?url_key=$1&url_key2=$2 [NC,L]
# list (from subcategory page; will have 3 variables)
RewriteRule ^shop/([^/.]+)/([^/.]+)/([^/.]+)$ list.php?mr=3&url_key1=$1&url_key2=$2&url_key3=$3 [NC,L]
# list (from category page; will have 4 variables)
RewriteRule ^shop/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)$ list.php?mr=4&url_key1=$1&url_key2=$2&url_key3=$3&url_key4=$4 [NC,L]
# business types
RewriteRule ^shop/restaurant-supply-business-type section.php?id=1 [NC,L]
# login
RewriteRule ^shop/customer/account/login login.php [NC,L]
# brands
RewriteRule ^shop/shopby/brand brands.php [NC,L]
# professional services
RewriteRule ^shop/professional-services professional_services.php [NC,L]
# pages
RewriteRule ^locations/([^/.]+)$ page.php?url_key=locations/$1 [NC,L]
RewriteRule ^locations page.php?url_key=locations [NC,L]
RewriteRule ^testimonials page.php?url_key=testimonials [NC,L]
RewriteRule ^contact-us page.php?url_key=contact-us [NC,L]
RewriteRule ^equipment-checklist page.php?url_key=equipment-checklist [NC,L]
RewriteRule ^shipping page.php?url_key=shipping [NC,L]
RewriteRule ^returns page.php?url_key=returns [NC,L]
RewriteRule ^lease-financing page.php?url_key=lease-financing [NC,L]
RewriteRule ^news page.php?url_key=news [NC,L]
RewriteRule ^advice page.php?url_key=advice [NC,L]
RewriteRule ^about-us page.php?url_key=about-us [NC,L]
RewriteRule ^careers page.php?url_key=careers [NC,L]
RewriteRule ^privacy page.php?url_key=privacy [NC,L]
RewriteRule ^terms-of-use page.php?url_key=terms-of-use [NC,L]
RewriteRule ^page/([^/.]+)$ page.php?url_key=$1 [NC,L]
RewriteRule ^section/([^/.]+)$ section.php?url_key=$1 [NC,L]
# Remove all .php extensions without interfering with .js or .css.
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !pagespeed
RewriteRule ^([^.]+?)/?$ $1.php [L]
# Remove index from url.
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^([^.]+?)/?$ index.php?$1 [L,QSA]
謝謝你的迴應,但我無法得到它的工作。我得到同樣的404。這是一個真正的URL不起作用的例子:/ shop/fountain-jar-2-qt-22916 – ToddN
更新它以顯示全部。我沒有商店目錄,它都在根目錄中。我的問題是類別,子類別,列表和產品都必須使用/ shop /。 – ToddN
試過了,同樣的事情。我與它相匹配的東西與我認爲的#category相同。我可以用#產品來處理這個問題: 'RewriteRule^shop/product /([^/.]+)$ product.php?url_key = $ 1 [NC,L]'但我只需要它在「/ shop /「,而沒有/ product /在網址中。 – ToddN