Solved

allowing for spaces in a url rewrite

Posted on 2006-11-30
14
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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
 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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