[英]How can i remove .php file extensions from my webpages on apache2
I'm running a php web application inside /var/www/html/app, i'm trying to modify the apache configuration so that.php file extensions are hidden from the browser. 我已經閱讀了有關堆棧溢出的多個其他答案,但沒有一個解決方案適合我。
我的應用程序位於/var/www/html/app
我的網站使用 HTTPS 並且我一直在修改的配置文件是:
/etc/apache2/sites-enabled/application-ssl.conf
conf文件的內容是:
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName myapplication.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/myapplication_com.crt
SSLCertificateKeyFile /etc/ssl/private/myapplication.com/myapplicationcom.key
SSLCertificateChainFile /etc/ssl/myapplication_com.ca-bundle
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
SecRuleEngine On
<IfModule mod_headers.c>
<Directory />
Header always set X-XSS-Protection "1; mode=block"
Header always set x-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set Referrer-Policy "strict-origin"
</Directory>
</IfModule>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<Directory /var/www/html/app>
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
目前我已經添加:
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
因為這似乎是 apache2 最推薦的解決方案。 我沒有在/var/www/html/app
中使用 .htaccess 文件,並且啟用了 Mod Rewrite
我在我的 web 應用程序中看不到任何變化,當我在沒有 php 的情況下訪問文件時,我在日志中收到 404 錯誤和以下錯誤:
AH00687: Negotiation: discovered file(s) matching request: /var/www/html/app/betfinder (None could be negotiated).
如何修改我的配置以使其正常工作?
嘗試這個:
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
我得到了它的工作:
<Directory /var/www/html/app>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.