Jump to content


Photo

Regarding .htaccess


Best Answer Jacques1, 21 December 2016 - 11:36 AM

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.

Go to the full post


  • Please log in to reply
6 replies to this topic

#1 pakiman

pakiman
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 December 2016 - 12:56 AM

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?



#2 requinix

requinix
  • Administrators
  • Confusing Administrator
  • 8,322 posts
  • LocationWA

Posted 21 December 2016 - 01:21 AM

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?

#3 pakiman

pakiman
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 December 2016 - 03:44 AM

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

#4 requinix

requinix
  • Administrators
  • Confusing Administrator
  • 8,322 posts
  • LocationWA

Posted 21 December 2016 - 04:19 AM

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?

#5 pakiman

pakiman
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 December 2016 - 06:04 AM

That the question I have

#6 Jacques1

Jacques1
  • Gurus
  • Turtles all the way down
  • 3,410 posts

Posted 21 December 2016 - 11:36 AM   Best Answer

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.



#7 pakiman

pakiman
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 21 December 2016 - 12:11 PM

Thank you soooo much. Something so basic that I totally forgot. Thanks again man.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users