Solved

Regular Expression Question

Posted on 2004-09-01
8
226 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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…

832 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