0

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.

1
  • I put some html code of qs1.php file. Commented May 23, 2015 at 19:18

2 Answers 2

0

I think you want : if file or directory not exit than redirect

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(\d+)/$ $1/$2 [R=301,L]
Sign up to request clarification or add additional context in comments.

2 Comments

did you try with '!'?, i added lost signs just some mins ago
yes, i did that. But no luck. I tried with ! and without.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.