我试图用我网站上的破折号替换所有下划线。我们面临着一些问题。
第1期
下面的是我网站上的网址
http://localhost/uk_london when clicked redirects to http://localhost/uk-london
但是下面的网址会在网址末尾添加一个额外的短划线并返回404错误
http://localhost/united_states http://localhost/united-states- (gives 404)
当我在最后删除短划线时,它可以正常工作。
第2期
仅当网址中只有一个网段时才会替换短划线。在下面的url中,没有一个下划线被短划线替换。
http://localhost/london_uk/city/products_availability_london
下面是我在htaccess中的代码
RewriteEngine On
RewriteBase /
RewriteRule ^assets - [L,NC]
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
RewriteCond %{ENV:uscor} ^Yes$
我对htaccess很新,想知道导致这些问题的原因。 任何帮助解决问题将不胜感激
答案 0 :(得分:0)
尝试更换:
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
只有:
RewriteRule ^(.*)_(.*)$ /$1-$2 [L,E=uscor:Yes]
重写引擎将循环并删除所有下划线,只要您没有比内部重定向限制更多的下划线(将导致500错误)。