Home > Software engineering >  Raspberry Pi web server remove .html/.php from URL
Raspberry Pi web server remove .html/.php from URL

Time:11-23

I'm using my Raspberry Pi as an webserver with a domain that i bought on strato.de with a dyndns. I attached a file named .htacces to my project with following code.

RewriteEngine on 
RewriteCond %{THE_REQUEST} /([^.] )\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

I also tried this one:

RewriteCond %{REQUEST_URI} !(\.[^./] )$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]


RewriteCond %{REQUEST_URI} !(\.[^./] )$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.htm -f
RewriteRule (.*) $1.htm [L]


RewriteCond %{REQUEST_URI} !(\.[^./] )$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]

Before hosting my website on the webspace from STRATO.de everything worked with the first version, which you can see above. But not its only giving me an 404.

Not found Raspbian Server

I just want to remove the ending .html/.php and other from my URL.

CodePudding user response:

  1. Log in into pi
  2. sudo nano /etc/apache2/sites-enabled/000-default
  3. Add:
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        # AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
    
  4. sudo a2enmod rewrite
  5. sudo /etc/init.d/apache2 restart oder service apache2 restart
  • Related