vikky Posted July 9, 2019 Share Posted July 9, 2019 Hi Greetings, Thank You Sir for the great support in the learning process. My question is - On the browse page I wanted to give a category name Books & DVDs for the non-coffee products. But when the page is loaded it is not displayed. If I URL ENCODE this name it will become Books+%26+DVDs. And my htaccess file is # For specific products: RewriteRule ^browse/(coffee|goodies)/([A-Za-z\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 I have tried RewriteRule ^browse/(coffee|goodies)/([A-Za-z0-9%\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 but it is working. I have tried other patterns also. I don't know how to modify it. Please provide the guidance. Thank You, Link to comment Share on other sites More sharing options...
Larry Posted July 10, 2019 Share Posted July 10, 2019 Try escaping the % sign. That's often the solution in situations like this, where a character may have special meaning. Link to comment Share on other sites More sharing options...
vikky Posted July 11, 2019 Author Share Posted July 11, 2019 Even after escaping the % it is not working. Link to comment Share on other sites More sharing options...
Larry Posted July 11, 2019 Share Posted July 11, 2019 Could you confirm what the FULL URL is with Books & DVDs? Link to comment Share on other sites More sharing options...
vikky Posted September 20, 2019 Author Share Posted September 20, 2019 Hi Greetings, Sir What I have done is: 1) I have created a category named Books & DVDs. 2) I have modified my htaccess file as mentioned above. So my FULL URL is localhost/browse/goodies/Books+%26+DVDs/3 I am receiving this general message - Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.13 This is very important because numerous books titles and Brand names have -------- & -------- sign as their identity. Thank You, Link to comment Share on other sites More sharing options...
Larry Posted September 20, 2019 Share Posted September 20, 2019 Okay, your current rule is: RewriteRule ^browse/(coffee|goodies)/([A-Za-z0-9\%\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 That looks correct but PCRE can be tricky. Your error message is odd, though, making me think maybe there's another problem. Does the browse script work for other categories? Can you load browse.php directly (it'll probably give an error but it should still run)? What happens if you go to localhost/browse.php?type=goodies&category=Books+%26+DVDs&id=3 directly? Link to comment Share on other sites More sharing options...
vikky Posted September 28, 2019 Author Share Posted September 28, 2019 Case 1 --- With the below rule : RewriteRule ^browse/(coffee|goodies)/([A-Za-z0-9\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 if I type URL - Just by taking out the % sign - localhost/browse/goodies/Books+26+DVDs/3 --- The page is loading perfectly On the window's tab it is showing Goodies to Buy::Books 26 DVDs Case 2 --- With the below rule : RewriteRule ^browse/(coffee|goodies)/([A-Za-z0-9\%\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 if I type URL - Just by taking out the % sign - localhost/browse/goodies/Books+26+DVDs/3 --- The page is loading perfectly On the window's tab it is showing Goodies to Buy::Books 26 DVDs Case 3 --- With the below rule : RewriteRule ^browse/(coffee|goodies)/([A-Za-z0-9\&\+\-]+)/([0-9]+)/?$ browse.php?type=$1&category=$2&id=$3 --- With or Without escaping ampersand if I type the URL as given below : localhost/browse/goodies/Books+%26+DVDs/3 --- The page is loading perfectly But On the window's tab it is showing Goodies to Buy::Books Not Books & DVDs Case 4 If I type the URL directly as localhost/browse.php?type=goodies&category=Books+%26+DVDs&id=3 --- The page is loading perfectly On the window's tab it is showing Goodies to Buy::Books & DVDs And The browse script is also working for the other categories. Sir you can also check the script at your end just add another category Books & DVDs Sir Case 3 is not completely solving the issue - what are your views ? In your Book on page no. 91 you have mentioned about the zero-width positive lookahead assertion can that be helpful in this situation. Thank You, Link to comment Share on other sites More sharing options...
Larry Posted October 6, 2019 Share Posted October 6, 2019 This is very good detective work and thanks for being so thorough. I'd start by ruling out cases 3 & 4, though. The links are going to come through with HTML entity versions, so %26. You'll never have & in the URL, so there's no need to test and handle that. I'm also not inclined to go to zero-width positive lookahead assertions; that'd probably just complicate things. I just did an online regex tester for case 2 and it matched the percent okay: https://regex101.com/r/AWJdX3/1/ Are you restarting Apache after making changes to the configuration? Link to comment Share on other sites More sharing options...
vikky Posted December 21, 2019 Author Share Posted December 21, 2019 Sir, Thank You for encouraging my efforts. I have restarted Apache after making changes and also cleared the cache. But it again showing the above mentioned error. I have visited the link mentioned in your post and there the match is made. So I do not have any idea what could be the problem. Link to comment Share on other sites More sharing options...
Larry Posted December 28, 2019 Share Posted December 28, 2019 Okay, it'll take me a couple of days but I'll test this out on my own server to see what's what. Link to comment Share on other sites More sharing options...
Recommended Posts