Jump to content
Larry Ullman's Book Forums

Recommended Posts

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,

Share this post


Link to post
Share on other sites

Try escaping the % sign. That's often the solution in situations like this, where a character may have special meaning.

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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?

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...