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 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办