大家好我是.htaccess
网址重写的新用户,我有像
但我希望它像这样
提前感谢...
我的
.htaccess
代码
#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^(\S*)\s+(\S*\s.*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*)\s(\S*)$" /$1-$2 [L,R=302,NE]
#RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php?name=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?name=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?name=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)?$ $1.php?name=$2 [L,QSA
答案 0 :(得分:1)
将前2个规则更改为此规则,以便将+
和空格转换为连字符:
# executes repeatedly as long as there are more than 1 spaces in URI
RewriteRule "^([^\s+]*)[\s+]+([^\s+]*[\s+].*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^([^\s+]*)[\s+]+([^\s+]*)$" /$1-$2 [L,R=302,NE]