Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Redirect Anchor Links to Specific Page WordPress


I've searched high and low and I'm beginning to think it's impossible.

Here's what I need to do:

1. I had 33 links that looked similar to this (old HTML site):

2. Those pages (or rather anchors to specific places in a single page) have been replaced (using WordPress) like so:

3. The old product anchor URLs need to point to the correct new product pages.

I've tried every mod_rewrite I can think of and nothing seems to work since (#) anchors are only used in the browser and not the server.

How can I accomplish what I need? Or am I screwed and pretty much need to remove the /store/ page (and subpages) from WordPress and replace them with the old HTML pages?

Or, can someone give me a solid JS solution for the timebeing?

Answers (6)


Utkarsh Kukreti answers:

You cannot redirect url's with hash tags, as the hash tag is never sent to the server. You can implement the redirect in javascript, but it'll only work for users who have javascript enabled.

Jason Manheim comments:

What would that js solution be?

Utkarsh Kukreti comments:

<script type="text/javascript">
window.location = "" + window.location.hash.substring(1) + "/";

Jason Manheim comments:

I apologize but that doesn't work. My fault. The new product pages are not the same name as the anchor tags.

So, is actually something like

Utkarsh Kukreti comments:

Try this. You can add more redirects to the redirects variable manually.

<script type="text/javascript">
var redirects = {
'product1': 'this-is-product-1/',
'product2': 'this-is-product-22/'

window.location = "" + redirects[window.location.hash.substring(1)];

Jason Manheim comments:

Doesn't work. It add"undefined to the URL.

When I go to I see it redirect to for a split second and then it ends up at

Also when going to is redirects to

Utkarsh Kukreti comments:

Try this:

<script type="text/javascript">

var redirects = {
'#product1': 'this-is-product-1/',
'#product2': 'this-is-product-22/'

if(redirects[window.location.hash]) {
window.location = "" + redirects[window.location.hash];


Jason Manheim comments:

Perfect. That'll work for now since not many folks have JS disabled. Thanks a bunch.


Daniele Raimondi answers:

You can try plugin [[LINK href=""]]redirection[[/LINK]]. It uses regular expressions to catch multiple urls for the old website and redirect them to your new page wit only one rule!

Daniele Raimondi comments:

oh sorry, I missed "#" in your urls. Utkarsh Kukreti is right, hashes never arrive to server...


Svilen Popov answers:

<blockquote>// $url - get current URL
preg_match_all('/productCategory.html#(.*)/', $url, $match);
header('Location:'. $match[1][0] .'/');</blockquote>


Clifford P answers:
should function the same as

That doesn't answer your question, but I'll keep looking into it.

Clifford P comments:

Could you just setup a category-products.php file or something that lists all products? And then redirect to ?

Or even an unlisted page like as your redirect -- and edit that page in the visual or HTML editor to list just these 33 products.


Elliott Richmond answers:

If these are separate categories then you'll never achieve what you need too as the links generated by WP will be new queries. If you add tags to individual products you could then create new links from the associated tags

$tags = get_tags();
$html = '<div class="post_tags">';
foreach (get_tags() as $tag){
$tag_link = get_tag_link($tag->term_id);

$html .= "<li><a href='#' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a></li>";
$html .= '</div>';
echo $html;

Not sure if I've understood this correctly and I'm sorry if my answer is way off the mark, it's difficult to understand what you're wanting to achieve.


rizaljohn answers:


If I understand it correctly, you can do it in a simple way...:)

Use a [[LINK href=""]]301 redirects[[/LINK]] plugin that let's your old links point to the new one..

Install it, then input all the old urls then point each to their designated new location... everything will be working great...

Hope it helps!