I have a following .htaccess
rules for 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 this rules I can access following url :
http://localhost/aponit/dev/zones/update/63
http://localhost/aponit/dev/cable-types/update/3
Now I have to create this type of url many more! So is there anyway in this .htaccess
rules to minimize the rules ?
I mean if I need 10 different url I have to add 10 rules to the .htaccess
file. e.g:
RewriteRule ^(?:another/)?another-f/(\w+)/?$ another/another-f.php?another-id=$1 [L,QSA,NC]
I want one rules in this.htaccess
file for this type of url.
Update:
In index.php file under zones folder I have following code to edit and 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 the form data I need this type of url :
http://localhost/aponit/dev/zones/update/63
Too add data I need this type of url :
http://localhost/aponit/dev/zones/add
and finally in .htaccess rules I need only one rules to follow this type of urls
Use these two 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 that name of the GET parameter will be same q
for all such URLs. Inside .php
file you can use $_GET['q']
to read it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With