我想重写http://example.com/articles.html#first-article
with http://example.com/articles/first-article
可以重写吗?
我尝试使用以下但对我不起作用:
RewriteRule ^articles/(.+)$ /articles\.html\#$1
The #
可以使用 NE 标志添加到替换 URL 中。查看:
-
这个阿帕奇链接 http://httpd.apache.org/docs/2.2/rewrite/advanced.html#redirectanchors具体描述了如何redirect anchors
.
-
此 W3C 协议链接 http://www.w3.org/Protocols/HTTP/Fragment/draft-bos-http-redirect-00.txt and this one http://www.w3.org/TR/cuap#uri.
-
SO中的这个答案非常完整 https://stackoverflow.com/questions/2286402/url-fragment-and-302-redirects.
-
SO中的另一个答案 https://stackoverflow.com/questions/15106056/mod-rewrite-in-htaccess-with-paging-system.
-
SO中的另一个答案 https://stackoverflow.com/questions/15033757/mod-rewrite-keeps-anchor-link/15034083#15034083 (mine).
所以,你可以尝试这个:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !articles\.html [NC]
RewriteCond %{REQUEST_URI} ^/articles/([^/]+)/? [NC]
RewriteRule .* /articles.html#%1 [R,NE,L]
重定向
http://example.com/articles/parameter
To
http://example.com/articles.html#parameter
String articles
假设是固定的,同时parameter
假设是变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)