简体   繁体   English

PHP-在rewriteRule中留出空间

[英]Php - allow space in rewriteRule

Hey there at the moment i have this rewrite (for seo) : 嘿,此刻我有此重写(对于seo):

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1

It works but only with url like this: 它有效,但仅适用于以下网址:

http://example.com/product/anyProduct

But when url is like this: 但是当URL是这样的:

http://example.com/product/any Product

There is an space and i get 404 - Error. 有一个空间,我得到404-错误。

So, how can i replace any space with a "-" ? 那么,如何用“-”替换任何空格?

I tried: 我试过了:

RewriteRule ^([a-zA-Z0-9_ -]+)$ index.php?id=$1

But this doesnt work for me, any idea? 但这对我不起作用,任何想法吗? greetings! 问候!

Try add + symbol to regex like ^([a-zA-Z0-9_ \\-+]+)$ . 尝试在正则表达式中添加^([a-zA-Z0-9_ \\-+]+)$类的+符号。

+ is an urlencoded space. +是一个数字化空间。

UPD : Try change regex to ^(.+)$ for every symbol UPD :尝试将每个符号的正则表达式更改为^(.+)$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM