RewriteRule to a hashbang / in-page bookmark

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

The new layout of this website has the contact details of the company listed in the footer of every page. Thus I want to redirect all requests for the old "1234.html" style contact page built using a hosting companies in-house builder, to the website index with the anchor of the contact details. "/index.html#contact".

Attempt one;

Code: [ Select ]
RewriteRule 1234\.html$ http://domain/index.html#contact-details [R=301,L]


Result

Code: [ Select ]
http://domain/index.html%23contact-details


It looks like Apache is URL encoding the pound symbol in my resulting URL, which prevents the browser from picking it up.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Found something called "Extended Redirection" on the Apache website (here) which makes me believe this will be more trouble than it's worth. It suggests setting up a new URL scheme, a CGI program, and by the looks of things it's just sending an intermediary webpage with an HTML link on it anyways.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I believe all you need to do is pass in the NE flag which prevents mod_rewrite from applying hexcode escaping of special characters in the result of the rewrite. So in your above example:

Code: [ Select ]
RewriteRule 1234\.html$ http://domain/index.html#contact-details [NE,R=301,L]
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Worked like a charm, thank you! :D

I thought there was some sort of flag like that, I gave up on it when I came across the CGI example at Apache's site earlier though. Been a few months, I've gotten rusty. ;)
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9089
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

No problem :)

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 108 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.