Solved

Regular Expression Question

Posted on 2004-09-01
8
225 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
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 count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

910 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

22 Experts available now in Live!

Get 1:1 Help Now