Web site in pure PHP with clean URL
I have enabled mod_rewrite in my Xampp Apache. When I run my phpinfo()
page, I saw mod_rewrite under Loaded Modules. So I think it's enabled.
Then I create a folder clean-url under htdocs. Inside clean-url folder I have 3 files
1) index.php here I put
<A href="test">Welcome</a>
2) Test. php
3) .htaccess
Here I put
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
I want to run the index page, and by clicking on that hyper link I want to display the test.php page with URL
mydomain/clean-url/test
I know I am in a wrong path. What am I开发者_如何学Python doing wrong? Also I don't know any idea about URL rewriting and .htaccess.
There is a dash in clean-url
, but your regex does not recognize it.
Change your .htaccess
to
RewriteEngine On
RewriteRule ^([a-z-]+)/([a-z-]+)$ /$1/$2.php [L]
and place it in htdocs/
instead of htdocs/clean-url/
.
i think you shouldn't use /$1/$2.php, just simply /$2.php
because you ask the rewrite to access the folder clean-url and open test.php in that folder.
try
^(.*)/(.*)$ /$1.php [L]
and see how it works ... then you should format in more complex regex.
精彩评论