mod_rewrite rewriterule?

时间:2012-07-24 10:56:29

标签: php html .htaccess mod-rewrite

你好,我的网站上有一个锚点。通过调用我的网站,网址将是:

http://site.com/page.php

点击按钮,网址会显示我想要隐藏的网址:

http://site.com/page.php#1

现在我发现我可以通过使用mod_rewrite工具来改变它。我试过这条规则没有成功:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]

将页面调用为html或php并隐藏.php背后的#1

RewriteRule ^(.*)$ ./php#1=php$1
如果有人能给我建议如何解决这个问题,我真的很感激。非常感谢。

4 个答案:

答案 0 :(得分:1)

你无法通过mod_rewrite实现这一点。

#之后的网址未通过服务器传递。

如果您仍想实现这一目标,您可能希望通过JavaScript来实现:

<a href="#checkthisout" onclick="scrollHere">Check this out</a>

JavaScript的:

function scrollHere() {
    // Scroll to the anchor 
    //(you may need to look for some script to achieve this)

    return false; // to prevent URL overwriting
}

这样的一个脚本是jQuery.scrollTo

答案 1 :(得分:0)

哈希标签永远不会发送到服务器,因此您根本无法创建基于它的规则。

答案 2 :(得分:0)

您可以执行以下操作来删除#tag。

<a href="javascript:void(0);">Your text</a>.

所以当你写“javascript:void(0);”在标签的href属性中,就是这样。

答案 3 :(得分:0)

HTML

<a href='page'>Home Page</a>

<a href='page/1'>Page 1</a>
<a href='page/2'>Page 2</a>
<a href='page/3'>Page 3</a>

重写为

RewriteRule ^$ page.php [L]
RewriteRule ^([a-z]+)/?([0-9]*)/?$ page.php?index=$2 [L]

检查php中的索引

<?php 
if (isset($_GET['index']))
{
      $pageNo =$_GET['index'];
}
//based on page NO display contents 

&GT;