Please tell me how, and is it possible to rewrite with .htaccess, this is the address

index.php#test1 

In this /test1

For example, this is how it corresponds with index.php to just index

 RewriteEngine On RewriteRule ^index$ /index.php [NC,L] 

Even so you can

 RewriteEngine On RewriteRule ^index$ /index.php?param=123 [NC,L] 

But he doesn't want to

 RewriteEngine On RewriteRule ^index$ /index.php#test1 [NC,L] 

I read that you can like this

 RewriteEngine On RewriteRule ^index$ /index.php%23test1 [NC,L] 

Put% 23 in the place of the hash, as # in the .htaccess file is a comment. But in that case the server’s answer is

 The requested URL /index.php3test1 was not found on this server. 

Prompt the correct decision if it exists. Or some interesting article.

  • 2
    Check the NE [No Escape] flag for the RewriteRule. - Costantino Rupert
  • In general, it works. But if you do this RewriteEngine On RewriteRule ^ index $ /index.php#test1 [NE, R] And the link will be such a <a href="index"> link </a> That link works, but why does the URL not exactly correspond to index, and becomes index.php # test1 - webkostya
  • and under what conditions do you have a hash in your request? - zb '
  • I just download content via jQuery, using the hashchange plugin and there the upload works by hash, so the links go like this <a href="#test1"> </a> here is a link to the resource benalman.com/code/projects / jquery-hashchange / examples / ... well, clicking on such a link displays # test1 in the URL, but I would like to remove this hash that would be at least simple / test1 - webkostya

2 answers 2

the plugin looked ... its whole point is to do # test1 in the URL, the server request looks like this:

 GET /code/projects/jquery-hashchange/examples/hashchange/ HTTP/1.1 Host: benalman.com Connection: keep-alive Cache-Control: max-age=0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.30 (KHTML, like Gecko) Chrome/26.0.1403.0 Safari/537.30 Referer: https://ru.stackoverflow.com/questions/192344/htaccess-rewriterule- %D0%B4%D0%BB%D1%8F-%D1%85%D0%B5%D1%88-%D0%B0%D0%B4%D1%80%D0%B5%D1%81%D0%B0 Accept-Encoding: gzip,deflate,sdch Accept-Language: ru,en-US;q=0.8,en;q=0.6 Accept-Charset: UTF-8,*;q=0.5 

As you can be sure the server is not transmitted, there are other plugins supporting history api with a fallback. for example , this in the case of them your rewriterule / framework framework should take into account that sometimes the last element in the request is "not real"

  • That is, my way out is to change the plugin, so you want to skim, or did I understand you wrong? - webkostya
  • Not really (although History.js is better than hashchange anyway), apparently you don’t fully understand that RewriteRule only rewrite server requests. If you use History.js, you will have to activate the elements on the page yourself using js, since the whole point of hashchange is in the activation of the page element depending on the # parameter, in general, you decide. I answered why it is impossible and where to dig. - zb '
  • Damn, I thought everything had already happened, but here damn some trifle spoiled everything, why damn you can not rewrite this fucking hash. Thank you for your assistance. - webkostya
  • you can rewrite it, but it will not work (through history api, it will be, but not cross-browser) - you are in a situation "pipe and jug", I strongly recommend to avoid such situations in all aspects of being. - zb '
  • How does VK.com work then ???? In terms of Ajax content loading. - webkostya

Hash and everything after it is not transmitted to the server. The content of VK's hash is tracked only with the help of JavaScript, and is passed as a GET parameter in the application's iFrame, for example. Hash changes are also tracked by JS, and cause, say, events in an application frame.

So .htaccess is irrelevant here.

  • The general scheme is this: the page is loaded, always the same, and the script inside it looks what's in the hash. And loads dynamic content. When you click on ajax links, change content, and change hash. This is how imitation of links is obtained, and you can go backwards and forwards and save the current state of the page in bookmarks. Watch how search engines index ajax sites separately. For example, Yandex writes . - Sergiks
  • Where in my comment did you see at least a hint that "ajax site is complete crap" or that they are poorly indexed? - Sergiks
  • 2
    you just need to make ajax links like <a href="/content"> , through ajax get parts of pages, and tell the application controller that if not ajax request, then generate a page with the necessary content. This will kill four birds with one stone - SEO, fast navigation, direct transitions and support for browsers with js turned off. - zb '
  • one
    Nasol one komennt, if I am not mistaken, this is what is called a direct link to the search engine. For example, the tag a has the rel attribute doing something like <a href = "mysite.com/mypage/" rel = "_ ajax" > Ajax link </a> Then we get all the links with rel = "_ ajax" and hang our Ajax functions on them, but the search engine does not do this and goes directly to the links ... - webkostya
  • one
    doduts.comoj.com made a demo :) - zb