views:

38

answers:

1

hi at the minute I have a list of rules in my .htaccess file but if I need to add a new page i then need to edit this file again and add yet another rulles. HEre is a few

RewriteRule ^admin/(.*).html$ index.php?x=admin&y=$1
RewriteRule ^admin/project/(.*).html$ index.php?x=work&p=project&$1
RewriteRule ^work/(.*).html$ index.php?x=work&p=$1

Is there some way that I can have 1 rule that will work for all. Is ther ways to do loops so that for each additional /something/extra in the url it will add it in the redirect??

Thanks.

A: 

The simple answer is no it is not possible to create a RewriteRule that can cope with a dynamic amount of variables. Your only real option is to capture the basics and capture everything afterwards as a single chunk and parse it with PHP. It may be possible to improve on what you currently have there, it depends whether the x=work in your second rule is a typo, and how consistent your query string variables are...

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)\.html$ index.php?x=$1&y=$2

This is the sort of pattern you might see in an MVC based system. But they usually have routing system to allow you to specify patterns to match (which is the same as having to add the RewriteRules in many ways).

Cags