pakiman Posted December 21, 2016 Share Posted December 21, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/ Share on other sites More sharing options...
requinix Posted December 21, 2016 Share Posted December 21, 2016 As you can tell, RewriteRule ^items/p/([0-9]+)/?$ /items.php?page=$1has 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? Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540627 Share on other sites More sharing options...
pakiman Posted December 21, 2016 Author Share Posted December 21, 2016 As you can tell, RewriteRule ^items/p/([0-9]+)/?$ /items.php?page=$1has 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 Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540629 Share on other sites More sharing options...
requinix Posted December 21, 2016 Share Posted December 21, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540630 Share on other sites More sharing options...
pakiman Posted December 21, 2016 Author Share Posted December 21, 2016 That the question I have Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540631 Share on other sites More sharing options...
Solution Jacques1 Posted December 21, 2016 Solution Share Posted December 21, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540637 Share on other sites More sharing options...
pakiman Posted December 21, 2016 Author Share Posted December 21, 2016 Thank you soooo much. Something so basic that I totally forgot. Thanks again man. Quote Link to comment https://forums.phpfreaks.com/topic/302793-regarding-htaccess/#findComment-1540638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.