我正在努力完成这项工作。目前我的 htaccess 包含以下代码:
#Debugging - Error reporting
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
#Commpression
<ifmodule mod_deflate.c="">
<filesmatch ".(js|css|html|png|jpg|jpeg|swf|bmp|gif|tiff|ico|eot|svg|ttf|woff|pdf)$"="">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>
Options All -Indexes +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
#RewriteCond %{THE_REQUEST} (\s|%20)
RewriteRule ^([^\s%20]+)(?:\s|%20)+([^\s%20]+)((?:\s|%20)+.*)$ $1-$2$3 [N,DPI]
RewriteRule ^([^\s%20]+)(?:\s|%20)+(.*)$ /$1-$2 [L,R=301,DPI]
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^.*\.(png|jpg|bmp|gif|css|js)$ [NC]
RewriteRule ^([^/]+/?.+)$ /index.php?req=$1 [L,QSA]
</IfModule>
如果我尝试这个 url,除了 1 件事之外,一切都很好,例如:
http://www.domain.com/ test/
浏览器将其翻译为:http://www.domain.com/%20test/ 基本上在域之后,如果路径以空格或 %20 开头,则失败。谁能指出将删除起始空格的解决方案?
更新
目标:
www.domain.com/ this is a test / hello there /
或者
www.domain.com/ this is a test
至
www.domain.com/this-is-a-test/
或者www.domain.com/this-is-a-test/hello-there