Home Apache rewrite to map # based URL into proper URLs
Reply: 0

Apache rewrite to map # based URL into proper URLs

user2251 Published in May 23, 2018, 4:17 pm

Long version (you can skip to TL;DR if you want to):

I am working with a Wordpress site that was set up by someone else. The website has multiple pages where page has tabbed content which is accessible through #. For eg:


Now, when search engines index they are indexing only www.example.com/services/category1/ and www.example.com/services/category2/. This creates a problem where we cannot have search engines point directly to the content within a given tab. What we want is for search engines to show links that takes users directly to (say) www.example.com/services/category2/#tab-service3.

Now, I don't think google can index such # based content on its own. So, I am thinking of using apache rewrites to try to resolve this issue. I have access to .htaccess file only (from a config perspective).


How to redirect www.example.com/services/category1/service3/ to www.example.com/services/category1/#tab-service3 using apache redirects (I have access to .htaccess file)?

This is what I am trying but it's not working:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  ^/services/category1/([a-z0-9])/? [NC]
RewriteRule .*       /services/category1#tab-%1           [R,NE,L]

Someone also adviced to look into pushState server config to fix this. I am not sure how to use pushState.


I have updated the rewrites to the following but it still doesn't work. It keeps showing Wordpress' 404 page

<IfModule mod_rewrite.c>
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /domainfolder/
RewriteCond %{REQUEST_URI}  ^/services/category1/([a-z0-9]+)/?$ [NC]
RewriteRule ^/services/category1/([a-z0-9]+)/?$ /services/category1/#$1 [NE,R,L]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.407999 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO