Solved

allowing for spaces in a url rewrite

Posted on 2006-11-30
14
203 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
Comment Utility
RewriteRule ^results-quick-([\ A-Za-z]+).htm$ searchResults.php?mode=quick&search=$1
0
 

Author Comment

by:scm0sml
Comment Utility
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
Comment Utility
if You want to use space, put '\ ' a space prefixed by backslash - that's what I did.
0
 

Author Comment

by:scm0sml
Comment Utility
ive been given a better solution

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

Expert Comment

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

Author Comment

by:scm0sml
Comment Utility
plus digits..............

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

Expert Comment

by:ravenpl
Comment Utility
And if You using dot, You can '.+' instead of '[.]+'
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 43

Expert Comment

by:ravenpl
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well In fact I answered Your question, hence no points? Whatever...
0
 

Author Comment

by:scm0sml
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

10 Experts available now in Live!

Get 1:1 Help Now