我需要将下划线替换为破折号。我已经尝试了这段代码,并尝试在这里更改一些参数,但我还不熟悉.htaccess语法,所以我自己做不到:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule !\.(html|php)$ - [S=6]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=underscores:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=underscores:Yes]
RewriteCond %{ENV:underscores} ^Yes$
RewriteRule (.*) /$1 [R=301,L]我之前的.htacces代码是这样的,它工作得很好,但直到现在还不需要将下划线替换为破折号:
# Added for SME compatibility
Options +FollowSymLinks
# Ignore Indexation of apache
IndexIgnore */*
# Turn on the RewriteEngine
RewriteEngine On
# Rules for ReRouting to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php我有这样的网址:http://mydomain.tld/nl_BE/get_quote,语言(第一个参数)不应该被短划线取代,而且语言参数可能会改变,所以我不能在.htaccess文件中硬编码语言名称。所以我希望URL是这样的:
http://mydomain.tld/nl_BE/get-quote/some-random-title
http://mydomain.tld/nl_NL/about-us/some-random-text提前感谢!
发布于 2015-09-17 22:54:38
您可以使用此通用递归规则,而不是使用这些多个规则:
Options +FollowSymLinks
RewriteEngine On
## RECURSION based rule
# if there is one underscore left then redirect
RewriteRule ^([a-z]{2}_[a-z]+)/([^_]*)_([^_]*)/?$ /$1/$2-$3 [NC,L,R=302]
# if there are more than one underscores then "repeatedly" replace it by -
RewriteRule ^([a-z]{2}_[a-z]+)/([^_]*)_(.*)$ $1/$2-$3 [L,NC]https://stackoverflow.com/questions/32632486
复制相似问题