php - How to minimize .htaccess rules? -


i have following .htaccess rules seo friendly url :

.htaccess rules :

options -multiviews errordocument 404 http://localhost/aponit/dev/not-found.php errordocument 500 http://localhost/aponit/dev/404.php rewriteengine on  rewriterule ^(?:zones/)?update/(\w+)/?$ zones/update.php?z=$1 [l,qsa,nc] rewriterule ^(?:cable-types/)?update/(\w+)/?$ cable-types/update.php?cbl=$1 [l,qsa,nc]  rewritecond %{request_filename} !-d rewritecond %{request_filename}.php -f rewriterule ^(.+?)/?$ $1.php [l] 

now, using rules can access following url :

http://localhost/aponit/dev/zones/update/63 http://localhost/aponit/dev/cable-types/update/3 

now have create type of url many more! there anyway in .htaccess rules minimize rules ?

i mean if need 10 different url have add 10 rules .htaccess file. e.g:

rewriterule ^(?:another/)?another-f/(\w+)/?$ another/another-f.php?another-id=$1 [l,qsa,nc] 

i want 1 rules in this.htaccess file type of url.

update:

in index.php file under zones folder have following code edit , add new data :

<a class="btn btn-success btn-xs" href="<?php echo site_url."zones/update/$zone_id"?>" >edit</a>   <h4 class="panel-title pull-right"><a href="<?php echo site_url.'zones/add' ?>" class="btn btn-primary">add new zones</a></h4>  

to edit form data need type of url :

http://localhost/aponit/dev/zones/update/63 

too add data need type of url :

http://localhost/aponit/dev/zones/add 

and in .htaccess rules need 1 rules follow type of urls

use these 2 generic rules instead of above type of rules:

rewritecond %{document_root}/aponit/dev/$1/$2\.php -f rewriterule ^([\w-]+)/([\w-]+)/?$ $1/$2.php [l]  rewritecond %{document_root}/aponit/dev/$1/$2\.php -f rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ $1/$2.php?q=$3 [l,qsa] 

please note name of parameter same q such urls. inside .php file can use $_get['q'] read it.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -