I had some url requests show up in my google sitemaps for one of my sites with "404 Not found" errors for a bunch of urls that had "%23comment-155" looking urls instead of "#comment-155"

Table of Contents

  1. Introduction
    1. The Solution
      1. Requests from apache log files
      2. After the fix
    2. Result
    3. More Info

The Urlencode RewriteRule Goal

So I had to redirect incoming links that contained
/article.html%23comment-155

to

/article.html#comment-155

The Solution

RewriteRule ^(.*).html([^c]+)comment-(.+)$ http://www.site.com/$1.html#comment-$3 [R=301,L,NE]

Requests from apache log files

"GET /htaccess/speed-up-sites-with-htaccess-caching.html%23comment-155 HTTP/1.1" 200 2617 "-"

After the fix

"GET /htaccess/speed-up-sites-with-htaccess-caching.html%23comment-155 HTTP/1.1" 301 683 "-"
"GET /htaccess/speed-up-sites-with-htaccess-caching.html HTTP/1.1" 200 24690 "-"

Result

Users browser is redirected using a Search Engine Friendly 301 Redirect to the correct URL, including anchor!

More Info

For more discussion of this problem check out http://www.webmasterworld.com/forum92/5188.htm

Replacing %23 with # in incoming links - AskApache

Charles Torvalds
24 Mar 2007

  • Site Map WireShark GNU Non-GNU Tor Project cURL TLDP - Documentation
  • Htaccess Files Hacking Htaccess Javascript Linux Optimization PHP Security Shell Scripting WordPress
  • Base64 Image Converter Raw HTTP Header Debugger Graphical ASCII Text Generator Mac Address Vendor Lookup Who Am I – Your IP Information Request Method Security Scanner .htpasswd file Generator Compress CSS DNS Tracer
Copyright © 2025 AskApache
  • Site Map
  • Htaccess Files
  • Hacking
  • Htaccess
  • Javascript
  • Linux
  • Optimization
  • PHP
  • Security
  • Shell Scripting
  • WordPress
  • Base64 Image Converter
  • Raw HTTP Header Debugger
  • Graphical ASCII Text Generator
  • Mac Address Vendor Lookup
  • Who Am I – Your IP Information
  • Request Method Security Scanner
  • .htpasswd file Generator
  • Compress CSS
  • DNS Tracer
Exit mobile version