Solved

Regular Expression Question

Posted on 2004-09-01
8
224 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

747 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

12 Experts available now in Live!

Get 1:1 Help Now