Skip to main content
Notice removed Draw attention by dr_
Bounty Ended with mateleco's answer chosen by dr_
added 1125 characters in body
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8.

File /etc/httpd/conf.d/mysite.conf:

<VirtualHost *:80>

    ServerName mysite.com
    DocumentRoot "/var/www/html"

    RewriteEngine on

    RewriteCond %{SERVER_NAME} =mysite.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

File /etc/httpd/conf.d/mysite-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName mysite.com
    DocumentRoot "/var/www/html"

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem

    ErrorDocument 403 /error403.html
    ErrorDocument 404 /error404.html
    ErrorDocument 405 /error405.html
    ErrorDocument 500 /error500.html

    RewriteEngine on 

    # First rule block
    RewriteRule ^/$ /index.php [R,L]

    # Second rule block    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
    RewriteRule \.php$ /%1/ [R=301,NC,L]
    RewriteRule ^(.*)/$ /$1.php [NC,L]

    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"

    TraceEnable off
</VirtualHost>
</IfModule>

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is the configuration of my Apache 2.4.37 webserver on Centos 8.

File /etc/httpd/conf.d/mysite.conf:

<VirtualHost *:80>

    ServerName mysite.com
    DocumentRoot "/var/www/html"

    RewriteEngine on

    RewriteCond %{SERVER_NAME} =mysite.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

File /etc/httpd/conf.d/mysite-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName mysite.com
    DocumentRoot "/var/www/html"

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem

    ErrorDocument 403 /error403.html
    ErrorDocument 404 /error404.html
    ErrorDocument 405 /error405.html
    ErrorDocument 500 /error500.html

    RewriteEngine on 

    # First rule block
    RewriteRule ^/$ /index.php [R,L]

    # Second rule block    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
    RewriteRule \.php$ /%1/ [R=301,NC,L]
    RewriteRule ^(.*)/$ /$1.php [NC,L]

    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"

    TraceEnable off
</VirtualHost>
</IfModule>

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

added 53 characters in body
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the solution suggested in the link had a bug -- that is, URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

added 12 characters in body
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is an excerpt of the configuration of my Apache 2.4.37 webserver:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

This is an excerpt of the configuration of my Apache 2.4.37 webserver on Centos 8:

RewriteEngine on

RewriteRule ^/$ /index.php [R,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*([^/.]+))\.php[\ ?]
RewriteRule \.php$ /%1/ [R=301,NC,L]
RewriteRule ^(.*)/$ /$1.php [NC,L]

The second rule block is taken from here and rewrites all URLs https://mysite.com/anypage.php to https://mysite.com/anypage/, hiding PHP file extensions and making permalinks nicer to see.

I've added the first rule block after noticing that the URL https://mysite.com/ returned a File not Found. Now it works.

However, a minor annoyance is that https://mysite.com/ redirects to https://mysite.com/index/ (since it loads the file index.php).

My question: How can this configuration be changed so that the URL https://mysite.com/ stays the same?

Notice added Draw attention by dr_
Bounty Started worth 50 reputation by dr_
added 12 characters in body
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147
Loading
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147
Loading