Reputation: 699
I would like to create url rewrite rule for my dynamic website using .htaccess
file from:
http://localhost/pincode/pinpo.php?po=Ameda
to:
http://localhost/pincode/postoffice/Ameda.php
How to change this?
Upvotes: 1
Views: 665
Reputation: 224
From the point of view of server the process is reverse, it rewrites your forged static url to dynamic url that works to retrieve the dynamic content.
Your url in your website (request_uri) should be
http://localhost/pincode/postoffice/Ameda.php
And you .htaccess file in the webroot should contain:
RewriteEngine on
RewriteBase /
RewriteRule ^pincode/postoffice/(.*)\.php$ /pincode/pinpo.php?po=$1 [L]
In case you want to rewrite dynamic to look static, you still need two rewrite rules in order your dynamic data retrieval works, this way:
RewriteEngine on
RewriteBase /
#static to dynamic, with nol arg to prevent infinite looping
RewriteRule ^pincode/postoffice/([a-z0-9]+).php$ pincode/pinpo.php?nol&po=$1 [L]
#dynamic to static:
RewriteCond %{QUERY_STRING} ^po=([a-zA-Z0-9]+)$
RewriteRule ^/pincode/pinpo.php$ pincode/postoffice/%1.php [L]
Upvotes: 0
Reputation: 41249
Use this in your pincode/.htaccess
file
RewriteEngine on
RewriteBase /pincode/
RewriteRule ^postoffice/(.*)\.php$ /pincode/pinpo.php?po=$1 [QSA,NC,L]
Upvotes: 1