0

This is how my htaccess file look right now:

RewriteEngine On
RewriteRule ^([\sa-zA-Z0-9_-]+)$ view.php?folder=$1
RewriteRule ^([\sa-zA-Z0-9_-]+)/$ view.php?folder=$1
RewriteRule ^([\sa-zA-Z0-9_-]+)\.html$ view.php?page=$1

It accepts the url as:

http://localhost/new.html to view.php?page=new
http://localhost/something to view.php?folder=something
http://localhost/something/ to view.php?folder=something

but it is not working for url as:

http://localhost/something%20else
http://localhost/something%20else/

it should be view.php?folder=something%20else

LIGHT
  • 5,604
  • 10
  • 35
  • 78
  • I am not getting any error, its showing blank page with the %20 in the URL. – LIGHT Sep 15 '16 at 19:52
  • No its not working.. `http://localhost/something%20else/` is trying to find the directory in that name, that isn't passed to view.php itself – LIGHT Sep 15 '16 at 20:57
  • its the same, it writes, no such directory as `something else` – LIGHT Sep 15 '16 at 21:12
  • yes, i mean that sir. – LIGHT Sep 15 '16 at 21:16
  • `Not Found The requested URL /blank hiuz/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.Not Found The requested URL /blank hiuz/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.` – LIGHT Sep 15 '16 at 21:16
  • there is no error, htaccess isn't even recognizing the pattern – LIGHT Sep 15 '16 at 21:50
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/123490/discussion-between-prakash-and-anubhava). – LIGHT Sep 15 '16 at 22:55
  • Its the 404 error sir. Please write me the htaccess that can process words with space between them as single variable. My code is not working – LIGHT Sep 16 '16 at 12:00

1 Answers1

1

According to this answer you should be using a url rewrite flag on your htaccess rewrite.

(shameless quote of link to follow:)

Try adding the B rewrite flag. This flag tells mod_rewrite to escape backreferences, the documentation says this:

_rewrite has to unescape URLs before mapping them, so backreferences will be unescaped at the time they are applied. Using the B flag, non-alphanumeric characters in backreferences will be escaped.

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
  • Didn't work with b flag too. Can you write the full block of code you meant? – LIGHT Sep 16 '16 at 12:00
  • Hello @Prakash., ok what about this Q&A? http://stackoverflow.com/questions/459667/how-to-encode-special-characters-using-mod-rewrite-apache – Martin Sep 16 '16 at 13:08