2016-02-28 03:24
浏览 38


I am using php $_GET function to call parameters from the database. And these perameters are usually variable within the url.

E.g. http://localhost:8080/series/dynamics/admin/cleanURL/Apple, where Apple is the variable from the database.

This works fine as long as GET function doesn't encounter a space, however in a real life situation I will have some variable such as "Green Apple" "Red Apple" etc..and URL will like,

http://localhost:8080/series/dynamics/admin/cleanURL/Green%20Apple and in that case I am getting 404 The requested URL was not found on this server error.

What I would like to achieve is to be able to conver whitespace into hyphen or +. I have done it through strreplace or urlencode() however the problem is I am still not able to get rid 404 error.

Just incase if it has anything to do with htaccess below is my code

 Options +MultiViews 
 Rewriteengine on
 RewriteBase /series/dynamics/admin/cleanURL/

 RewriteCond %{REQUEST_FILENAME} !-f [OR]
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteCond %{THE_REQUEST} /series/dynamics/admin/cleanURL/(\S*)\s [NC]

 Rewriterule ^(\w+)/?$ index.php?product=$1 [L,QSA]
 RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]

 #rewrite group and subgroup e.g. http://.../value1/value2/
 Rewriterule ^([a-zA-Z0-9]+(.*)+)/([^/]+(.*)+)/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongwan0574 2016-02-28 15:00

    a better question is why are you using folder structures that have whitespace? I'd just change the name of the files to be something like Green_Apple and your problem is fixed. It's better practices.

    点赞 评论

相关推荐 更多相似问题