How to apply the Rewrite rules in php page links so that while rendering the page links get converted to rewrite rule -
i using apche mod_rewrite applying reules in .htaccess file,
options +followsymlinks -multiviews rewriteengine on rewritebase / rewritecond %{the_request} ^[a-z]{3,}\s([^.]+)\.php [nc] rewriterule ^ %1.html [r,l,nc] rewritecond %{request_filename}.php -f rewriterule ^ %{request_uri}.php [l] rewriterule ^(.*)\.html$ $1.php [nc]
it works when enter url
http://localhost:6060/index.php
redirect
http://localhost:6060/index.html
however need convert links in page if links appeared in .php converted .html extention
<a href="index.php">home</a>
while rendering convert
<a href="index.html">home</a>
no need write php code @ all. apache has module called mod_proxy_html.
you'll haver ensure apache override settings allow use of directive, , have loaded following modules:
loadmodule proxy_module modules/mod_proxy.so loadmodule proxy_http_module modules/mod_proxy_http.so loadmodule headers_module modules/mod_headers.so loadmodule deflate_module modules/mod_deflate.so loadfile /usr/lib/libxml2.so loadmodule xml2enc_module modules/mod_xml2enc.so loadmodule proxy_html_module modules/mod_proxy_html.so
then, in .htaccess
, need ensure html proxy maps enabled, , define map in order apache change these links. in case:
proxyhtmlenable on #if using new version of module only... sets apache #to handle url's in href's, , links in scripts (like javascript), if #changing .html values these 2 directives necesarry, second 1 #especially adds overhead proxyhtmlextended on proxyhtmlinterp on
from here... gets bit tricky because aren't changing path, extension. apply action of changing .php links .html links, use proxyhtmlurlmap
directive, , need this:
proxyhtmlurlmap .php .html $
Comments
Post a Comment