简体   繁体   中英

How to remove all .php extension from a dir and all of its subdirectories?

My web is dir structured is as follows :

moving/
includes/
controllers/
includes/
etc...


I have the following questions about /moving and all of its sub-diretories:

  1. How can i request any php script without the .php extension?
  2. How can i request ...dir/index.php?q=about as just ...dir/about ?
  3. 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!

如果您将mod_rewrite路由非PHP扩展请求发送到正确的请求,则可以将其放在根Web目录中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM