FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Home  »  Htaccess  »  Replacing %23 with # in incoming links

by 2 comments

[hide]

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"


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

March 24th, 2007

Comments Welcome

  • Keno

    how do i display the title of an article in the URL with .htaccess replacing spaces with _ underscore and special characters. thanks

  • http://www.ApkAndroidGame.com sunny Tewathia

    You havn't included much written part in the post that makes these codes very difficult to place at right place.

    Thanks

My Online Tools
My Picks
Twitter

  • : Ratpoison, a lean mean WM for Linux (urvxt), I love it
  • : You understand, what I need to know is exactly what happens to the passengers in an elevator when it falls into emptiness - Einstein
  • : It's not process, its content. That's what makes good products. -jobs
  • : Just bought some great BOSE headphones from best buy


Related Articles
Newest Posts

WordPress Development
Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman






It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain