Sam Sam - 7 months ago 41
PHP Question

Change rules on local server so URLs don't include file extensions using MAMP?

I'm running a local server via MAMP PRO. Currently my urls (expect index.php) require the file extension suffix. For example:

How do I change rewrite rules it is

I've attempted adding a htaccess file but it has no effect on file structure. Is there another way to do this via MAMP?


this rewrites [every_name].php to [every_name] and the same for .html files

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

if you only want one filename to be extensionless use this:

RewriteEngine On
RewriteRule ^page$ page.php [L]

Somewhat more trivial: don't use RewriteRules, and let Apache handle all request path extensions (along with file type and language auto-negotiation):

Options +MultiViews