0

I made a .htaccess file that redirects, for example, link:

website.com/module#controller

to:

website.com/?url=module#controller

As # is the PHP comment declarer, I get a problem when need to load:

$bootstrap->init($url) // $url = module#controller;

I tried to use addslashees($url);, but still when I:

echo $url;

I still get an output of:

module

How I should clear that string, to treat the # sign as part of the string?

3
  • 3
    What? Strings in PHP are never parsed for comments. You need to post your actual code, and some more description of what you're doing, because currently your question makes no sense Commented Jan 17, 2014 at 18:47
  • I just dont know why, the part #controller gets threated as comment. Try it yourself, with this setup: .htaccess : RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L] | index.php : echo $_GET['url']; | Tell me what you get, same problem or it works for you? Commented Jan 17, 2014 at 18:50
  • 1
    A RewriteRule won't ever see anything after the # mark in a URL, as the browser never sends it to the server. Commented Jan 17, 2014 at 18:51

2 Answers 2

2

$url = module#controller; is not valid PHP.

$url = 'module#controller'; will (correctly) not treat the # as a comment initiator.

Additionally, a # in a URL isn't going to work the way you expect. That's the marker for the URL hash/anchor, which is not passed to the web server. This is likely why you get output of module - your problem is at the browser level, not PHP.

Sign up to request clarification or add additional context in comments.

1 Comment

if $url = (isset($_GET['url'])) ? $_GET['url'] : 'index'; it is normal to be with quotes, but in my question it is written without, basically thinking that it is understandable that it will be 'module#controller'...
0

The hashtag fragment identifier is a client-side concept only. The browser would never send a hashtag value to the server.

If you are relying on this functionality, your are going to be disappointed as server has absolutely no way to do redirection based on the hashtag, as it never even sees the hashtag.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.