homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

(Help) How to make 2 rule in htaccess
My rule not execute

 10:24 am on May 30, 2012 (gmt 0)

I have problem with my rule in htacces
like this

RewriteEngine On
RewriteRule ^([a-zA-Z]+).html$ action.php?act=$1 [L]
RewriteRule ^([a-zA-Z]+)-([a-zA-Z]+)/([A-Za-z0-9-]+)([0-9-]+).html$ index.php?module=$1&act=$2&titel=$3&id=$4

2nd rule can execute, but 1st rule can't execute

what wrong with my rule.
please help me

thanx befor



 7:19 pm on May 30, 2012 (gmt 0)

What do you mean by "can't execute"? Do you mean the rule is never invoked, even when you expect it to apply, or your php can't handle it?

You need to step back and say in English what you want to do. Once you're perfectly clear on that part, then you can write the rule.

The second rule is missing an [L], so it will be exposed to anything that comes after it in mod_rewrite.

The two rules between them only admit two possible filenames:

(top-level file, letters only)


(or www.example.com/blahblahblah-blah/12345.html
or www.example.com/x-moreblatherhere/zippity-doo-dah-34---blah-.html
or any other variation, so long as the first directory contains a non-final hyphen and the filename ends in a numeral or hyphen).

If all your filenames fall into one of these patterns, the rules are almost correct. I stress almost because Rule 2 needs to be specific about where $3 ends and $4 begins. Otherwise it will always break at


putting all but the last character into $3.


 7:50 pm on May 30, 2012 (gmt 0)

Escape the literal period.

Add the [L] flag to the second rule.

Change [a-zA-Z] to [a-z] and add the [NC] flag to both rules.

The gap between $3 and $4 is ambiguous, as noted above. Sort that out.

If it still doesn't work the requested URL simply doesn't match the RegEx pattern or there is an error in your PHP script.


 3:58 pm on May 31, 2012 (gmt 0)

lucy24 & g1smd thanks for your advice.

i m so sorry my english so bad,
this i mean that my problem

1st i want to convert follwoing url :

RewriteRule ^([a-zA-Z]+)-([a-zA-Z]+)/([A-Za-z0-9-]+)([0-9-]+).html$ index.php?module=$1&act=$2&titel=$3&id=$4

this rule can run and no problem,

2nd i want to convert follwoing url :

my rule:
RewriteRule ^([a-zA-Z]+).html$ action.php?act=$1

my problem is,

1. if i give url ttp://domain.com/(rumahh)/(login).html
this never executed
2. how to write that rule & flag like that for both

i tried like g1smd say, but not run too


[edited by: diwan at 4:19 pm (utc) on May 31, 2012]


 4:01 pm on May 31, 2012 (gmt 0)

Please edit your post to use example.com not your domain, not some other domain, so that it is readable. The forum suppresses the URL auto-linking function when you use example.com here.

The edit button is just under your user name.

A request for
will be divided as:
rumahh/ (rumah) - (newsevent) / (Memilih-rumah-yang-tepat-guna-bakti) (3) .html
This might not be what you want, due to the ambiguous RegEx pattern that you have used (assuming this rule is in the htaccess file inside the rumahh folder).

The gap between $3 and $4 is ambiguous, as noted above. Sort that out.

As for your other rule, it should work, but if that rule is in the root htaccess file it will never match the requested URL.

Escape the literal period in the .html part.

Add the [L] flag to the second rule.


 4:26 pm on May 31, 2012 (gmt 0)

thanks g1smd... so how rule must i write it for both

Ok g1smd, i'll try, thanks for ur advice


 6:12 pm on May 31, 2012 (gmt 0)


Is the last capture always just a single numeral? If so, your rule will work as intended but it can be written a little more narrowly:


with [NC] flag.

Can the earlier part of capture $3 ever include numerals? If so you will have to add them, as in your original post. Conversely, can the last character ever be a non-numeral? The server will then have to backtrack once, but that's unavoidable and it's only one character.

If the url starts with /rumahh/ you need to include that in the Rule unless the htaccess is located within the /rumahh/ directory. But you normally wouldn't do this if the request is going to end up being redirected.

:: detour to g### translate ::

Aha. They didn't like the second h. (It surprised me too.)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved