【发布时间】:2013-12-11 13:17:14
【问题描述】:
是否可以在不更改代码的情况下将url中的空格更改为破折号(-)?
URL 用于标识页面,因此无法仅更改 url,因为该页面将不再被找到,因此 str_replace 在此解决方案中不可用。
使用str_replace 两次,一次将空格更改为破折号,然后在页面加载器上将其更改回空格也不起作用,某些页面的页面名称中已经有破折号:)
我希望这可以通过 htaccess 实现,但我不知道如何实现。 是否可以使用 htacces 在浏览器中显示与实际 url 不同的 url?
例如:www.example.com/pages/hello%20world
应该显示为www.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>
其中一种产品的示例网址 = http://www.example.nl/software/category/details/this%20is%20a%20product-name
【问题讨论】:
-
显示一些代码,进一步扩展您要替换哪些数据的位置...它来自哪里,您如何将其传递给什么,以及为什么,谁,在哪里... ?
标签: php html .htaccess url-rewriting