1

What I have is a url like this:

domain.com/index.php?chapter=chapter-name

and a url link this:

domain.com/index.php?marker=marker-name

What I want is:

domain.com/#chapter-name

and this:

domain.com/#chapter-name/marker-name

How can I do this with .htaccess?

I now have the following:

RewriteEngine On
RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1
RewriteRule ^([a-zA-Z0-9_-]+)?$ index.php?chapter=$1
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?chapter=$1

Thanks!

Steven de Jong
  • 69
  • 2
  • 13
  • 3
    '#' is an URL fragment, using it in this way may not have the effect you're after : http://blog.httpwatch.com/2011/03/01/6-things-you-should-know-about-fragment-urls/ – CD001 Feb 20 '14 at 16:54
  • You cant do it via htaccess, use Javascript instead. – anubhava Feb 20 '14 at 16:55
  • Would the second request actually be: domain.com/index.php?chapter=chapter-name&marker=marker-name ? – Andrew Bessa Feb 20 '14 at 17:01
  • Apache can rewrite to anchor tags: http://stackoverflow.com/questions/2686075/mod-rewrite-with-anchor-link – Andrew Bessa Feb 20 '14 at 17:03

2 Answers2

0

To get the chapter working, try this rule:

RewriteRule ^index.php\?chapter=([a-zA-Z0-9_-]+)$ http://www.%{HTTP_HOST}/#$1

Your second needs is a arbitrary... how does the marker "know" which chapter... Maybe you meant this on your second request:

domain.com/index.php?chapter=chapter-name&marker=marker-name
Andrew Bessa
  • 271
  • 3
  • 9
0

You can't. Basically # is a client thing, and never sent to the server. .htaccess therefore will not work.

An Phan
  • 2,557
  • 2
  • 25
  • 27