Как я могу удалить расширения .php из моих веб-страниц на apache2 - PullRequest
0 голосов
/ 06 ноября 2019

Я запускаю веб-приложение php в / var / www / html / app, пытаюсь изменить конфигурацию apache, чтобы расширения .php были скрыты от браузера. Я прочитал несколько других ответов о переполнении стека, но ни одно из решений не работает для меня.

Мое приложение находится в /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. Я не использую файл .htaccess внутри /var/www/html/app, и Mod Rewrite включен

Я не вижу никаких изменений в своем веб-приложении, и когда я получаю доступ к файлам без php, я получаю ошибку 404 иследующая ошибка в журнале:

AH00687: Negotiation: discovered file(s) matching request: /var/www/html/app/betfinder (None could be negotiated).

Как мне изменить мою конфигурацию, чтобы она работала?

Ответы [ 2 ]

0 голосов
/ 06 ноября 2019

Я получил это с этим работать:

<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>
0 голосов
/ 06 ноября 2019

Попробуйте это:

RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
...