RewriteRule to a hashbang / in-page bookmark

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post October 8th, 2011, 4:47 am

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.
Strong with this one, the sudo is.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 8th, 2011, 4:47 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post October 8th, 2011, 5:03 am

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.
Strong with this one, the sudo is.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8922
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 8th, 2011, 10:22 am

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]
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post October 8th, 2011, 10:29 am

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. ;)
Strong with this one, the sudo is.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Joined: Dec 20, 2002
  • Posts: 8922
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Post October 8th, 2011, 10:31 am

No problem :)
Ozzu Hosting - Want your website on a fast server like Ozzu?

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 134 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.