How to remove all .php extension from a dir and all of its subdirectories?
My web is dir structured is as follows :
I have the following questions aboutmoving/
includes/ controllers/ includes/ etc... 开发者_JAVA百科
/moving
and all of its sub-diretories:
- How can i request any php script without the .php extension?
- How can i request
...dir/index.php?q=about
as just...dir/about
? - Where woul i place my .htaccess file?
I understand that my first question might be a duplicate, but in order to contextualize my second and third question i had to ask it.
Using WampServer 2.0 Thanks in advance.
apache will not parse your php script if they don't have the ".php" extention.
but, you can use mod_rewrite:
This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.
This module operates on the full URLs (including the path-info part) both in per-server context (httpd.conf) and per-directory context (.htaccess) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.internal proxy throughput.
If all your website files are ending with .php and you want to take off the .php extension, then you should create and .htaccess file, or if you already have it, add this rule:
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
Supposing your website pages are let's say site/about.php, site/contact.php, site/news.php, the rule above will just transform those to site/about, site/contact, site/news
Hope it helps!
Provided you have mod_rewrite routing non-php extension request to the proper request, you would put it in your root web directory.
精彩评论