1
我正在尝试用下划线重写网址以便为购物网站划线。将单个和连续的下划线重写为破折号
产品名称目前对空格有下划线。一个典型的网址如下:
http://test.local/category-name/product_name_a
我目前的.htaccess如下,并成功地重写这:
http://test.local/category-name/product-name-a
RewriteEngine On
RewriteBase/
#Rewrite Underscores to dashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^_]*)_([^_]*)$ $1-$2 [L,R=302,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^_]*)_+(.+)$ $1-$2 [L]
# Redirect to index.php & standard Opencart stuff
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
但是有些产品有连续的下划线在他们这样的as
http://test.local/category-name/product__name__b
或混合两种,如:
http://test.local/category-name/product__name_a
我已经尝试和失败,让这些改写到:
http://test.local/category-name/product--name--b
http://test.local/category-name/product--name-a
不破现有的重写。任何帮助非常感谢。
完美,谢谢! – jx12345 2015-03-19 13:00:04
由于此更改将是永久性的,因此使用301重定向会更好吗?并通过编辑第一条规则来实现:RewriteRule ^([^ _] *)_([^ _] *)$ $ 1- $ 2 [L,R = 301,NE] – jx12345 2015-03-19 13:52:36
是继续, 301规则,因为一切工作正常。 – anubhava 2015-03-19 13:58:59