apache - htaccess doesn't work on localhost -
i started playing url rewriting today , watched/read few tutorials still don't how rewriting works.
i created .htaccess
file , placed in root directory. i'm working on local machine, using apache.
i want http://localhost:5216/index.php
redirect http://localhost:5216/index
in .htaccess file have following:
options +followsymlinks rewriteengine on rewriterule ^index?$ index.php
this doesn't work. tried refreshing page, checked httpd.conf
file has allowoverride all
selected. i've read few tutorials , think right way seems don't. wrong file?
i want
http://localhost:5216/index.php
redirecthttp://localhost:5216/index
rewriterule ^index?$ index.php
your rewriterule
opposite... rewrites /index
(or /inde
since you've made last x
optional) index.php
. note internal rewrite, not external redirect.
your rewriterule
close want do. allows link /index
(in application) , still serve actual /index.php
file.
taking step further... had contact document called "contact-the-monster.php" in document root - physical file on filesystem. wanted use simple url /contact
access document - url use throughout application. don't want user see filename "contact-the-monster.php". in root .htaccess
file need internally rewrite requests /contact
/contact-the-monster.php
, like:
rewriterule ^contact$ contact-the-monster.php [l]
the l
(last
) flag included since don't need else.
make sure multiviews
not enabled. can disabled in .htaccess
using options
directive:
options +followsymlinks -multiviews
multiviews
can conflict mod_rewrite produce unexpected results. particularly when url maps file less file extension.
Comments
Post a Comment