1

I have following file in root directory :

Dev (root)   
   update.php
   zones.php

This zones.php file is showing using following url:

http://localhost/aponit/dev/zones (I hide .php extension using .htaccess rules)

In zones.php file I have a edit link to edit a form via query string. The link is bellow :

<a class="btn btn-success btn-xs" href="<?php echo SITE_URL."zones/update?z=$zone_id"?>" >Edit</a>

When I click on this link it's showing following url :

http://localhost/aponit/dev/zones/update?z=55

But in browser it's showing me error message :

Internal Server Error

Because my .htaccess rules is not define appropriate rules for that desired link.

What I want now :

I want the url should be user friendly. E.g

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

How can I create this link using .htaccess ?

Current .htaccess rules :

ErrorDocument 404 /not-found.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

1 Answer 1

0

You can have another rule to handle zones/update/55:

Options -MultiViews
ErrorDocument 404 /not-found.php
RewriteEngine on

RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Sign up to request clarification or add additional context in comments.

7 Comments

Let me try with this.
okey, it's showing correct url now ? But page is broken! I see it's loading the zones.php file but I need to load the update.php file to show form to edit.
Can you tell me about this line : ?:zones/ ?
One last question : Now I have this url : localhost/aponit/dev/zones/update/55. so If remove 55 or update or load the url with localhost/aponit/dev/zones its showing me "Internal Server error". So is there any way to show error message to the user ?
(?:zones/)? makes zones/ part optional before update and also try my updated rules now. I am going offline. Accept the answer if it works out for you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.