Probs with mod_rewrite regex in htaccess file

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

Probs with mod_rewrite regex in htaccess file

Post by lettie_dude »

Hi

Just starting out with mod_rewrite and have couple of books and looked at various tutorials on the web. Seems pretty straight forward. I do have an issue though which may or may not be due to my wonderful shared hosting!

As some rules seem to work and some don't and they have already misinformed me on 2 occasions I thought I'd run the rewrite rule by you guys to see if it is indeed something I am doing wrong as opposed to their setup. So rule is:

Code: Select all

RewriteEngine On
 
# Rewrite URLs
RewriteRule ^myurl-to-display/([a-z0-9]+)-range\.html$ /actual_url.php?var=$1 [NC, L]
I am trying to match any number of letters or numbers so the entered url could be something like:

http:www.domain.com/myurl-to-display/ABC1234-range.html

At present this rule crashes the site and the error log states RewriteRule: bad flag delimiters

Can any one confirm if this is correct or not.

Many Thanks
rvijay_eee
Forum Newbie
Posts: 4
Joined: Tue May 13, 2008 4:16 am

Re: Probs with mod_rewrite regex in htaccess file

Post by rvijay_eee »

You have given a space in square bracket, I have removed it and added th rewritebase in the code.
you also added a slash before actual_url.php. I have removed it

Code: Select all

RewriteEngine On
 RewriteBase /myurl-to-display
# Rewrite URLs
RewriteRule ^([a-z0-9]+)-range\.html$ actual_url.php?var=$1 [NC,L]
http:www.domain.com/myurl-to-display/ABC1234-range.html
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

Re: Probs with mod_rewrite regex in htaccess file

Post by lettie_dude »

Cheers rvijay_eee

Book I was reading from has a space entered obviously a misprint as it is working fine now!
Post Reply