Jump to content
Sign in to follow this  
pakiman

Regarding .htaccess

Recommended Posts

So I am creating a website that the individual would like to have his website as /shop/123 instead of shop.php?id=123. I have been using .htaccess and it's working to show it that but it's blocking my other scripts from working

RewriteRule ^items/p/([0-9]+)/?$ /items.php?page=$1

It is blocking this from being used 

<input type="text" class="search" id="inputSearch" />
<div id="divResult">
</div>

It's blocking my javascript from running and its this 

$(function(){
$(".search").keyup(function() 
{ 
var inputSearch = $(this).val();
var dataString = 'searchword='+ inputSearch;
if(inputSearch!='')
{
      $.ajax({
      type: "POST",
      url: "search.php",
      data: dataString,
      cache: false,
      success: function(html)
      {
      $("#divResult").html(html).show();
      }
      });
}return false;    
});

jQuery("#divResult").live("click",function(e){ 
      var $clicked = $(e.target);
      var $name = $clicked.find('.name').html();
      var decoded = $("<div/>").html($name).text();
      $('#inputSearch').val(decoded);
});
jQuery(document).live("click", function(e) { 
      var $clicked = $(e.target);
      if (! $clicked.hasClass("search")){
      jQuery("#divResult").fadeOut(); 
      }
});
$('#inputSearch').click(function(){
      jQuery("#divResult").fadeIn();
});
});

Can anyone help me with this?

Share this post


Link to post
Share on other sites

As you can tell,

RewriteRule ^items/p/([0-9]+)/?$ /items.php?page=$1
has absolutely nothing in common with

url: "search.php",
So what do you mean by it's "blocking" scripts? Are you getting 404s? Or what? What else have you changed in the .htaccess recently?

Share this post


Link to post
Share on other sites

As you can tell,

 

RewriteRule ^items/p/([0-9]+)/?$ /items.php?page=$1
has absolutely nothing in common with

url: "search.php",
So what do you mean by it's "blocking" scripts? Are you getting 404s? Or what? What else have you changed in the .htaccess recently?

So while your on items/ the search box works but when you use the items/buy... it does not work

Share this post


Link to post
Share on other sites

Oh.

 

Here's a question I'll pose for you:

 

If the browser is currently displaying the page at

http://www.example.com/items/p/123/
and you tell it to make an AJAX request to search.php

url: "search.php",
what do you think the full URL to that page will be?

Share this post


Link to post
Share on other sites

To make it short: Virtual paths like /items/p/ and relative physical paths like search.php don't go well together. The browser will end up trying to access nonsense URLs like /items/p/search.php, because it assumes it's actually within the directory /items/p/.

 

Use absolute paths instead. For example, if your PHP script is directly below the document root, that's

/search.php

In the long run, you should also consider switching to virtual (“pretty”) URLs altogether. Then you can completely decouple the physical script paths from the URLs.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.