Browser not accepting "+" in the title in the URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Browser not accepting "+" in the title in the URL

Post by simonmlewis »

We are upgrading our website, part of this is shortening the URLs.

But I've come across a hitch that I didn't think would be a problem anyway.

If a URL has a + in it, like "BATTERY-+-CHARGER", it doesn't like it.
Yet the live site that hasn't been updated yet, is fine with it.

This is the htaccess, which I suspect is the cause of this.

Code: Select all

# old url style
RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&product=$5&h=$6 [QSA]

# new url style
RewriteRule ^product/([^/]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&cname=$1&sname=$2&product=$3&h=$4 [QSA]
In firefox, I'm being taken to a :
The page isn't redirecting properly
page.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Browser not accepting "+" in the title in the URL

Post by Celauran »

Can you post an example URI?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

Sadly not sorry. but a dummy version would be:

http://www.website.co.uk/product/shirts ... ts-+-socks

This would page would fall over.

But if it were this:
http://www.website.co.uk/product/shirts ... -and-socks
it would be fine.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Browser not accepting "+" in the title in the URL

Post by Celauran »

simonmlewis wrote:but a dummy version would be:

http://www.website.co.uk/product/shirts ... ts-+-socks
Good enough. Didn't need to be a real URL. Obfuscating client names etc is always fine.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

Cool - leave it with you then to see if you can spot the issue.
I'm sure having both URLs in the htaccess is fine, as they are different structures. It's flawed me. At first I thought it was a missing product, but if it is not there it goes to a nicer page than a 404.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Browser not accepting "+" in the title in the URL

Post by Weirdan »

Wasn't plus sign used as a substitution for space character? What's the redirect url your browser is getting?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Browser not accepting "+" in the title in the URL

Post by Celauran »

Weirdan is exactly right.

[text]array (size=5)
'page' => string 'product' (length=7)
'cname' => string 'shirts-and-socks' (length=16)
'sname' => string 'new-shirts-socks' (length=16)
'product' => string '3131' (length=4)
'h' => string 'xl-shirts- -socks' (length=17)[/text]
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

Then why does it work on our live site? that uses UTF-8.

In between each category name would be a /111/ type number configuration, but with the title of the product on the end.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

the other issue is, we have some products with titles like "Simons best++" for example.
So I cannot just remove all the + signs. Specially since at the moment... they work!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

Weirdan wrote:Wasn't plus sign used as a substitution for space character? What's the redirect url your browser is getting?
How do I find that out?
The URL remains on that page. but shows the error quoted.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Browser not accepting "+" in the title in the URL

Post by Celauran »

simonmlewis wrote:
Weirdan wrote:Wasn't plus sign used as a substitution for space character? What's the redirect url your browser is getting?
How do I find that out?
Network tab in your browser's console (F12 in Firefox). Type URL into address bar, check for 301 or 302.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

It's trying to load the page, about 20 times, all as 301.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Browser not accepting "+" in the title in the URL

Post by Weirdan »

So it appears there's a redirect loop. I wonder if you actually need to do external redirect (301/302 response sent to browser). From my experience, it's usually internal redirect (page served to browser without changing the url in the address bar) that people want.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Browser not accepting "+" in the title in the URL

Post by simonmlewis »

Sorry? I'm not with you. This happens ONLY on pages with the + in the URL. If a product page doesn't exist, it throws it to an error page. But this isn't "going" anywhere. The URL remains, and it goes to a standard browser error page.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Browser not accepting "+" in the title in the URL

Post by Weirdan »

There shouldn't be any 30x responses. The fact that there are external redirects suggests there's something else at play.

You may try adding B (escape special chars) and L (stop processing) flags to your rules, but it's a stab in the dark. You shouldn't have used reserved characters in urls in the first place. And using them in two parts of the urls (path and query string, that have different sets of allowed characters) only complicates this situation.
Post Reply