Solved

Regular Expression Question

Posted on 2004-09-01
8
230 Views
Last Modified: 2010-08-05
Hey ya'll...I'm trying to use the mod_rewrite function in apache to basically make my web pages case insensitive.  I've made the htaccess, and used this:

RewriteEngine on
# mod_rewrite engine enabled

RewriteRule $1/(.*) [nocase]
# mod_rewrite rule for case insensitivity

However, it doesn't seem to be working, obviously.  I think it's my RewriteRule - does anyone know what the reg ex would be to match our url?  We have several different urls (url1.com, url2.com, url3.com), and people could use cases wrong.  For example, these all would need to go to url1.com/Testdir/Testpage1.php:

url1.com/testdir/testpage1.php
url2.com/TeStDiR/TeStPaGe1.PHp
url2.com/TESTDIR/TESTPAGE1.PHP
url3.com/testdir/TESTpage1.PHP

Any thoughts?


CoolATIGuy
0
Comment
Question by:CoolATIGuy
[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
  • 4
  • 3
8 Comments
 
LVL 3

Assisted Solution

by:gnudiff
gnudiff earned 200 total points
ID: 11960582
The problem is with changing the case of the URls. Do you really need that?
Generally you can't change the _case_ of the expression with regexps; you would need to use the extended rewriting and have some CGI script to do that;

Otherwise, the regexp for what you posted is quite simple:

url(\d+)\.com/(.*)$           url1.com/$2
0
 
LVL 4

Assisted Solution

by:chipple
chipple earned 300 total points
ID: 11960586
I don't think it can be done automatically, you have to tell Apache which URLs must be considered accepted, and redirect to the correct URL.

Something similar may do. (Not tested.)

# Exclude when correct REQUEST_URI and SERVER_NAME
RewriteCond ${REQUEST_URI} !^/Testdir/Testpage1\.php$ [OR]
RewriteCond ${SERVER_NAME} !^url1\.com$
# nocase compare, redirect to correct domain and path
RewriteRule ^testdir/testpage1\.php$ http://url1.com/Testdir/Testpage1.php [NC,R,L]

Good luck.
0
 
LVL 4

Assisted Solution

by:chipple
chipple earned 300 total points
ID: 11960596
Btw I assumed that url1.com, url2.com, url3.com are domain names.

Also, for all your rewriting needs, have a look here:
http://httpd.apache.org/docs/misc/rewriteguide.html
http://httpd.apache.org/docs/mod/mod_rewrite.html
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 8

Author Comment

by:CoolATIGuy
ID: 11960637
Well, I'm a bit confused...I know that Windows has this functionality, while linux file system doesn't.  I was hoping that either mod_rewrite or mod_speling would do the trick...I just want to not have people get confused over case, like when they forget the to cap the first letter of the folder name.  I would prefer not to do it on a page by page basis, but I'm a bit foggy headed.  If you could "dumb down" what you said a bit, I'd be greatly appreciative...

CoolATIGuy
0
 
LVL 4

Accepted Solution

by:
chipple earned 300 total points
ID: 11960654
Now that you mention it, why not use mod_speling, if available?

http://httpd.apache.org/docs/mod/mod_speling.html

CheckSpelling on
0
 
LVL 8

Author Comment

by:CoolATIGuy
ID: 11960723
Well, take that with a grain of salt...I have yet to convince my web host to re-enable that.  In their words, they said they are using mod_rewrite as a better substitute, although not as simple. :-P  Go figure...anywho, so I just do "CheckSpelling on" and I'll have all the bells and whistles?


CoolATIGuy
0
 
LVL 4

Assisted Solution

by:chipple
chipple earned 300 total points
ID: 11960744
Yup, should be. That's mod_speling's only option, it's "on" or "off". :)

Good luck convincing your host.
0
 
LVL 8

Author Comment

by:CoolATIGuy
ID: 11960793
Thanks!

CoolATIGuy
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

635 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