.htaccess 重写规则在生产中不起作用
.htaccess rewrite rule not working in production
使用 Apache 2。
我需要在 http://website.dev/file-name
.
中重写 http://website.dev/file-name.php
中所有请求的 url
下面是 .htaccess
文件:
RewriteEngine On
SetEnv "ENVIRONMENT" "production"
SetEnv "BASE_URL" "http://website.dev"
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.php$
ErrorDocument 404 /404.php
该解决方案在登台服务器上完美运行,但在生产环境中(mod_rewrite 已启用)请求 http://website.dev/file-name
似乎不起作用并导致显示 404.php
文件。
我错过了什么?是否有任何逻辑或服务器配置问题?
应该这样做
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ .php [NC,L]
使用 Apache 2。
我需要在 http://website.dev/file-name
.
http://website.dev/file-name.php
中所有请求的 url
下面是 .htaccess
文件:
RewriteEngine On
SetEnv "ENVIRONMENT" "production"
SetEnv "BASE_URL" "http://website.dev"
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.php$
ErrorDocument 404 /404.php
该解决方案在登台服务器上完美运行,但在生产环境中(mod_rewrite 已启用)请求 http://website.dev/file-name
似乎不起作用并导致显示 404.php
文件。
我错过了什么?是否有任何逻辑或服务器配置问题?
应该这样做
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ .php [NC,L]