I'm a bit confused on url writing in .htaccess and have a question about rewriting urls.
My first question is I'm trying to do is have a one .htacces to make the urls go from http://www.website.com/index.php
to http://www.website.com/Home/
and another .htaccess to go from http://www.website.com/index.php
to http://www.website.com/home.html
. Here's a sample code I did to lose the ".php":
AddHandler application/x-httpd-php .php .html .htm
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My second question I'm running into is I have my a tags are set up has <a href="index.php"></a>
and it shows the the "index.php" not "/Home/" like I want to. Am I suppose to put "/Home/" into the href in order for it to work?
I only build websites has a hobby so I don't know much开发者_JAVA百科 about htaccess. Thanks a bunch.
I think you misunderstood how mod_rewrite works and how it is used: mod_rewrite is for rewriting or redirecting requested URIs. So if a URI path like /Home/
or /home.html
is requested, mod_rewrite can be used to rewrite these requests internally to /home.php
.
But to have mod_rewrite do this, you will actually need to request /Home/
or /home.html
respectively and not /home.php
. So /Home/
and /home.html
have to be already used in the HTML documents instead of /home.php
.
精彩评论