php - URL Rewrite Regular Expression to suit all -
brief explanation
i trying come smart way of controlling web page rewrites few rewrites possible.
so, example, if have following page translations:
'domain.com/test/' => 'domain.com/test.php' 'domain.com/errors/404/' => 'domain.com/errors.php?code=404' you could have individual rewrites every page... however, minimise instead having 1 regular expression suit all. regular expression match above be:
^([a-z0-9\-]+)\/?([a-z0-9\-]+)?\/?$ and matches placed url (note code replaced request on errors page):
domain.com/$1.php?request=$2 and append query string...
obviously in cases need individual rewrites, can minimise using clever regular expressions , structured pages.
my problem
similar above example, have pages within site rewritten exact regular expression. following pages translate so:
'domain.com/shipments/open/' => 'domain.com/shipments.php?request=open' 'domain.com/settings/user/' => 'domain.com/settings.php?request=user' etc... however, reasons not go into, have pages written so:
'domain.com/shipment/edit' notice says shipment not shipments! despite this, still want rewritten shipments page. translation this:
'domain.com/shipment/edit' => 'domain.com/shipments.php?request=edit' i cannot think of way other rewrite specifies shipment alias shipments...
one of reasons not want individual rewrites not talking shipments, there many documents need alias, , therefore rather not go down multiple rewrite route web.config file pretty darn large.
i have come following solutions (but not happy them):
- have page in root directory called shipment.php , include contents of shipments.php
- write rewrites each page alias...
i cannot think of (better) way of doing this, can of you?
since have 1 exception, why not add 1 exception ?
we use "rewrite rewrite technique" (i came name lol)
rewriteengine on rewriterule ^([a-z0-9-]+[^s/])s*/?([a-z0-9-]+)?/?$ $1s/$2 [nc] rewriterule ^([a-z0-9-]+)/?([a-z0-9-]+)?/?$ $1.php?request=$2 tested on localhost , rewriteruletester.
Comments
Post a Comment