2017-10-09 5 views
0

내가 대시와 숫자 (또는 하나 개의 번호)의 세트로 끝나는 URL을하지만 나던 작업에 일치하는 것을 시도하고있다 :htaccess로 모드 - 재 작성 URL을

예 : 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] 

답변

0

당신은이 규칙을 사용하여 단지 끝 부분을 일치시킬 수 있습니다 : 당신이 끝을 일치 시키려면

RewriteRule ^shop/.*-([0-9,]+)/?$ product.php?url_key=$1 [NC,QSA,L] 
+0

응답 해 주셔서 감사합니다하지만 난 그것을 작동시킬 수 없습니다. 내가 얻은 같은 404. 다음은 작동하지 않는 실제 URL 예제입니다./shop/fountain-jar-2-qt-22916 – ToddN

+0

모두 표시하도록 업데이트했습니다. 나는 상점 디렉토리가 없다. 루트에 모두있다. 내 문제는 카테고리, 하위 카테고리, 목록 및 제품 모두 사용해야합니다/shop /. – ToddN

+0

같은 일을 시도했습니다. 나는 내가 믿는 #category와 같은 일을하는 것과 관련이있다. 나는 이걸로 일할 #product를 얻을 수있다 : 'RewriteRule^shop/product/([^/.]+)$ product.php? url_key = $ 1 [NC, L]'그러나 나는 "/ 가게/"/ product/url없이. – ToddN

0

을 (- 숫자 또는 숫자)가 포함 된 uri는 followin 만 사용합니다. g :

RewriteRule ^shop/(.*)(-([0-9]+)|([0-9]+))$ product.php?url_key=$2 [R,L,NE] 

하면 (민수기 또는 숫자의 한 자리는) 다음과 같은 사용

RewriteRule ^shop/(.*)(-([0-9]+)|\b[0-9]\b)$ product.php?url_key=$2 [R,L,NE]