0

I am trying to rewrite a bunch of pdf URLs. Most are already working, but I am having trouble with a few of them. The problems all contain #page=xx in the URL. I want the #page=xx to be matched, and I do not want that string appended to the destination.

For example:

RewriteRule ^/pdfdir/test.pdf$  http://newlocation.com/dir1/newdir/abc.pdf [R=301,L]
RewriteRule ^/pdfdir/test.pdf#page=3$  http://newlocation.com/dir1/newdir/def.pdf [R=301,L]

When I try to access my site with /pdfdir/test.pdf, it matches and rewrites correctly. Now I want the request for page 3 inside test.pdf to go to a complete separate def.pdf in the new location. Right now, it is appending the #page=3 to the first match destination, which is abc.pdf.

Any suggestions would be most appreciated.

thanks

steve

poncha
  • 7,198
  • 1
  • 31
  • 36

1 Answers1

0

The part after # is fragment

A fragment, by definition, is location inside a page.

mod_rewrite does not operate on fragment part.

In RewriteRule subject, you operate only on URI. Which means, the first rule is the only one applicable here, and hence it matches every time.

poncha
  • 7,198
  • 1
  • 31
  • 36
  • Thank you, that makes complete sense. Is there any way to accomplish what I am trying to do? – stevemcc1991 Mar 12 '14 at 14:34
  • Do the URLs have to be like that? If you change the URL structure, you could either include page information in the uri, or put it in the query-string at least (and that would be match-able via `%{QUERY_STRING}` in `RewriteCond`... – poncha Mar 12 '14 at 14:37
  • Thanks, I do have to have the page number fragment, and I cant change the structure. I think what I need to do is still have the 90 or so RewriteRules that don't contain the #page= string and have RewriteConds that will match those 15 or so strings above them in the rule set. Does that make sense? – stevemcc1991 Mar 12 '14 at 14:44
  • Then you're out of luck... This portion of url is not even sent to the server. See discussion on this regarding parsing this in php: http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url – poncha Mar 12 '14 at 14:51