Solved

allowing for spaces in a url rewrite

Posted on 2006-11-30
14
204 Views
Last Modified: 2010-03-04
i have the following rule:
RewriteRule ^results-quick-([A-Za-z]+).htm$ searchResults.php?mode=quick&search=$1

it works fine unless there is a space in the ([A-Za-z]+), so say rockley park for e.g

how can i allow for spaces in there?
0
Comment
Question by:scm0sml
  • 7
  • 5
  • 2
14 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 18052270
RewriteRule ^results-quick-([\ A-Za-z]+).htm$ searchResults.php?mode=quick&search=$1
0
 

Author Comment

by:scm0sml
ID: 18052310
so what is this saying?

any number of spaces and chars? as that is what i need. i also need to accomodate numbers incase they enter rockley park 2 for e.g
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18052339
if You want to use space, put '\ ' a space prefixed by backslash - that's what I did.
0
 

Author Comment

by:scm0sml
ID: 18052359
ive been given a better solution

[.] allows all chars.....including spaces and digits!! :)
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18052364
I thought You want not all, but space + A-Z + a-z
0
 

Author Comment

by:scm0sml
ID: 18052459
plus digits..............

in any order...........
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18052677
And if You using dot, You can '.+' instead of '[.]+'
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 43

Expert Comment

by:ravenpl
ID: 18052683
RewriteRule ^results-quick-([\ 0-9a-z]+).htm$ searchResults.php?mode=quick&search=$1 [NC]
last [NC] means no-case-sensitive
0
 
LVL 16

Accepted Solution

by:
HackneyCab earned 500 total points
ID: 18059411
A valid URL should never contain spaces. Characters such as spaces should be urlencoded with escape codes (the ones that begin with a percent-sign and then two hex digits).

If you're handing out URLs with spaces, then you may have other problems to worry about.
0
 

Author Comment

by:scm0sml
ID: 18059486
no im not dont worry.

ive just replaced the space with _ and then vice versa at the other end using php str_replace.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18093144
Well In fact I answered Your question, hence no points? Whatever...
0
 

Author Comment

by:scm0sml
ID: 18093173
well i think that hackneycab gave me the right answer in that a url shouldnt contain spaces..................

but im not prepared to argue over a few points...........

if ee agree with you then im happy to split the points if its possible.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18093364
Well, for You knowledge. URL may contain spaces. It's advised that URL have no whitespaces. This way You have easier debuging and better security.
Think first. I don't need those points. Have enought.
0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18094037
ravenpl, URIs (which includes URLs) may not contain whitespace characters.

If you want to check, take a look at the relevant RFCs, RFC1738 (which is now technically obsolete), and at RFC3986 (general definition of URI syntax). Many characters are permitted in the path of a URL, but whitespace is not among those characters.

However, you did try hard to solve the question as scm0sml asked it, so if a points split occurs, I would not think it unreasonable.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now