Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2009
    Location
    Newcastle
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Is it possible to direct every URL to a #anchor?

    What I'm looking to do is every redirect every URL on the website to a anchor I have setup. Is this possible through a htaccess file?

    Some more information on this topic would b great, I've had a look around Google and there does seem to be a way, but nothing that I have seen that is clear cut.

  • #2
    New Coder
    Join Date
    Mar 2010
    Location
    Virginia, USA
    Posts
    25
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello.

    To my knowledge, a redirect to an anchor is not possible with just Apache directives. The anchor is handled on the client-side browser. Apache ignores any anchors attached to the end of a rewriterule (escaping the pound symbol has no effect either).

    All the solutions I've seen involve coding of some sort - usually with a dab of javascript. This is again due to anchors being a client-side feature that most server-side languages are not equipped to deal with.

    If you are working with a PHP-based site, your easiest option would be the auto_prepend_file directive in php.ini. All you would need is a simple PHP script to read the current URL (if necessary) and perform a redirect to the new URL with anchor specified.

    To prevent a redirect loop, throw in some javascript to ensure that an anchor has not already been specified. This blog post details the integration of javascript to read the anchor tag within PHP.

    This type of solution should work for any server-side language with some adaptation. Sorry that I haven't seen an easier solution. Good luck!

  • #3
    New Coder
    Join Date
    Mar 2010
    Location
    Virginia, USA
    Posts
    25
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Thumbs up

    Quick follow up -

    There's a section on redirection to anchors in the Apache2 mod_rewrite docs.

    So maybe there is a simple solution after all.

    - C. Aaron Smith


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •