doupin5667 2015-05-23 19:11
浏览 36
已采纳

HyperLinks无法正常工作(使用带有htaccess的漂亮网址时重定向)

Here is my php code(qs.php). This file contain pretty url links.

<html>
<head></head>
<body>
    <?php  
    $file = 'qs1'; //this is a php file qs1.php
    $id = '12345678'; //testing ID
    $complete_url = $file."/".$id;

    ?>
    <a href ="<?php echo $complete_url;?>"> This is a test link </a>

</body></html>

This link appear link this - http://localhost/qs1/12345678

QS1 is a php file (qs1.php).

QS1.php

<html>
<head>
<title>QS1 file</title>
</head>
<body>
<a href="#"><img src="images/blog/girl.png" class="img-circle" alt="" /></a>
<a href="#"><img src="images/blog/girl2.png" class="img-circle" alt="" /></a>
<a href="#"><img src="images/blog/girl3.png" class="img-circle" alt="" /></a>

</body></html>

Below is the htaccess code.

Options -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/(\d+)/$ $1/$2 [R=301,L]

Everything is working fine. My link is working properly. http://localhost/qs1/12345678 link is accessible by this. I am able to access the page. In my current page wherever i use this code(#). I can say other links on that page.

<a href="#"><img src="images/blog/girl.png" class="img-circle" alt="" /></a>

It is redirecting to localhost only instead of passing the same to current page.

Not sure what i am missing.

  • 写回答

2条回答 默认 最新

  • dougu1985 2015-05-24 02:11
    关注

    I figured it out. This is not a htaccess or url redirection issue. It is JavaScript issue. # is used for jquery. My function was not working properly.

    So, it was redirection to localhost. I found this link which help me understand what is going wrong. What does <a href="#" class="view"> mean?

    Here is why it was not directing. I used # in jquery. Like below.

    $(document).ready(function(){ 
    $("#").click(function(){
        alert("Hello!");
    });
    

    $("#") isn't a valid selector. So, i will have to use anchor tags.

    Below is the working code.

    $(document).ready(function(){ 
    
        $(".vote").click(function(event) {
        event.preventDefault();
        alert("Hello!");
    });
    

    event.preventDefault() used because i am using

    Hope this help someone.

    I got help to find out the issue by DelightedD0D. You can see the complete answer on this link.

    bind click event to anchor tags on my page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败