apache - Use specific PHP file for specific directories -


i trying create mod_rewrite rules rewrite based on first level directory name plus failover rewrite standard file in case none of directory names matched.

example:

i have units.php, models.php , other.php. other.php file should handle non-assigned requests.

http://www.mydomain.com/units/4435 should redirect /units.php?id=4435

http://www.mydomain.com/models/594 should redirect /models.php?id=594

http://www.mydomain.com/anything should redirect /other.php?id=anything

http://www.mydomain.com/anything/893 should redirect /other.php?id=anything/893

let me know if makes sense. unsure of how structure rules , conditions achieve want.

this have tried sfar. works urls starting 'units' or 'models' 500 error if try other url:

rewriteengine on   rewritecond %{script_filename} !-d   rewritecond %{script_filename} !-f   rewriterule ^(units)/(.+)$ /units.php?id=$2 [l,nc]  rewriterule ^(models)/(.+)$ /models.php?id=$2 [l,nc] rewriterule ^(.+)$ /other.php?id=$2 [l,nc] 

you may try this:

options +followsymlinks -multiviews rewriteengine on rewritebase / rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewritecond %{request_uri}  ^/(units|models)/([^/]+)/? [nc] rewriterule .*  /%1.php?id=%2                          [l,nc]  rewritecond %{request_uri}  !(units|models)    [nc] rewritecond %{request_uri}  !other\.php        [nc] rewriterule ^(.*)   /other.php?id=$1  [l,nc] 

for permanent redirection, replace [l,nc] [r=301,l,nc]


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -