Regular expression help

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

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Regular expression help

Post by itsmani1 »

I am facing problem in regular expressing, please help me.

My website has two files, index.php, myshop.php when user access mywebsite.com it should take them to index.php and when they try mywebsite.com/anyshop it should take them to that shop.

Here is what i did for this but it did not work.

Code: Select all

RewriteEngine on
RewriteBase /
RewriteRule ^/?(index\.php)?$ index.php [L]
RewriteRule ^/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([a-z]+)/([0-9]+)$ shop.php?shop=$1&catid=$2&order=$3&page=$4
RewriteRule ^/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([a-z]+)$ shop.php?shop=$1&catid=$2&order=$3
RewriteRule ^/([a-zA-Z0-9]+)/([a-z]+)/([0-9]+)$ shop.php?shop=$1&order=$2&page=$3
RewriteRule ^/([a-zA-Z0-9]+)/([a-z]+)$ shop.php?shop=$1&order=$2
RewriteRule ^/([a-zA-Z0-9.]+)/([0-9]+)$ shop.php?shop=$1&page=$2
RewriteRule ^/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([0-9]+)$ shop.php?shop=$1&catid=$2&page=$3
RewriteRule ^/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)$ shop.php?shop=$1&catid=$2
RewriteRule ^/([a-zA-Z0-9.]+) shop.php?shop=$1
RewriteRule ^item/([0-9]+)$ item_detail.php?id=$1


If i make a folder/directory named shopping and try this, it works fine but don't want to keep shopping there, i want it to work without shopping. like myshop.com/anything

Code: Select all

RewriteRule ^shopping/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([a-z]+)/([0-9]+)$ shop.php?shop=$1&catid=$2&order=$3&page=$4
RewriteRule ^shopping/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([a-z]+)$ shop.php?shop=$1&catid=$2&order=$3
RewriteRule ^shopping/([a-zA-Z0-9]+)/([a-z]+)/([0-9]+)$ shop.php?shop=$1&order=$2&page=$3
RewriteRule ^shopping/([a-zA-Z0-9]+)/([a-z]+)$ shop.php?shop=$1&order=$2
RewriteRule ^shopping/([a-zA-Z0-9.]+)/([0-9]+)$ shop.php?shop=$1&page=$2
RewriteRule ^shopping/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)/([0-9]+)$ shop.php?shop=$1&catid=$2&page=$3
RewriteRule ^shopping/([a-zA-Z0-9]+)/([0-9-a-z-A-Z]+)$ shop.php?shop=$1&catid=$2
RewriteRule ^shopping/([a-zA-Z0-9.]+) shop.php?shop=$1
RewriteRule ^item/([0-9]+)$ item_detail.php?id=$1
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Regular expression help

Post by ridgerunner »

If this is in a .htaccess file, you need to get rid of the initial '/ ' at the beginning of each RewriteRule. Apache strips these out.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: Regular expression help

Post by itsmani1 »

thanks

any solution to my problem?

thanks agian
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Regular expression help

Post by JakeJ »

Look in to positive lookbehinds and lookaheads with regex. I think that will solve your problem.
Post Reply