Jump to content

Regarding .htaccess


Go to solution Solved by Jacques1,

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?

Link to comment
https://forums.phpfreaks.com/topic/302793-regarding-htaccess/
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?
Link to comment
https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540627
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

Link to comment
https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540629
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?
Link to comment
https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540630
Share on other sites

  • Solution

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.

Link to comment
https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540637
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.