Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expression Question

Posted on 2004-09-01
8
Medium Priority
?
232 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 800 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 1200 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 1200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

721 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