Age*_*DeO 0 html php .htaccess url-rewriting
是否可以将 url 中的空格更改为破折号 (-),而不在代码中进行更改?
URL 用于标识页面,因此不可能仅更改 url,因为将不再找到该页面,因此str_replace
在此解决方案中不可用。
使用str_replace
两次,一次将空格更改为破折号,并在页面加载器上将其更改回空格也不起作用,某些页面的页面名称中已经有破折号:)
我希望这可以通过 htaccess 实现,但我不知道如何实现。htacces 是否可以在浏览器中显示与实际 url 不同的 url?
例如:www.example.com/pages/hello%20world
应该是 visable aswww.example.com/pages/hello-world
但GET
变量仍然应该是hello%20world
。
这是我当前的 .htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+home/httpd/vhosts/domain.nl/httpdocs/app/View/Products/([^%20]*)%20([^\s]*) [NC]
RewriteRule ^/home/httpd/vhosts/domain.nl/httpdocs/app/View/Products/%1-%2 [L,NE,R]
RewriteRule "^(/home/httpd/vhosts/domain.nl/httpdocs/app/View/Products/)/([^-]*)-+(.*)$" "/$1/$2 $3" [L,NE,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
其中一项产品的示例 url = http://www.example.nl/software/category/details/this%20is%20a%20product-name
你可以在你的文件中尝试这样的事情DOCUMENT_ROOT/.htaccess
:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+path/([^%20]*)%20([^\s]*) [NC]
RewriteRule ^ /path/%1-%2 [L,NE,R]
RewriteRule "^(path)/([^-]*)-+(.*)$" "/$1/$2 $3" [L,NE,NC]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2656 次 |
最近记录: |