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
2
Answers
Use these two generic rules instead of above type of rules:
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.Just use this rule:
It will rewrite:
Note 1: This standardizes your paths. You no longer make the first part (
zones/
vscable-types/
optional)Note 2: that you have to standardize the name of your first query parameter. I use
z
above. Then, within the PHP files, you use it as needed. Thecable-types/update.php
will use it just as you used thecbl
parameter before