简体   繁体   中英

Accessing URLS by www.example.com/page instead of www.example.com/page.php

What handles the disabling of the extension? Is it APACHE or the PHP install? How would one go about configuring the web server where the .php extension is not required? Is there an option that would make both www.example.com/page.php and www.example.com/page work as the URL?

Apache also has a setting called MultiViews that will serve domain.com/index.* as domain.com/index , domain.com/example.* as domain.com/example , etc.

I've occasionally run into issues where MultiViews beats out mod_rewrite rules, so I tend to turn it off.

Check out some articles from A List Apart on this topic: You use Apache (in your case) to setup ReWriteRule's and then you have PHP parse the url to fetch the correct information. (again, in your case. You can do this with many languages and http servers)

http://www.alistapart.com/articles/succeed/

http://www.alistapart.com/articles/urls/

brianreavis is correct. Here's an example for your .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

I just throw it all at PHP and parse it however I want in there:

.htaccess

RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css)$ @frontend.php

I use this in my .htaccess

<Files ~ "^[^.]+$">
ForceType application/x-httpd-php5
</Files>

That way I can remove all extensions (.php) from my files, and it will still work.

I use $_SERVER['PATH_INFO'] to retrieve the remainder of the path as parameters. Eg /page/param1/param2 where page is an actual php file.

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