-1

I have a VPS Server (Debian 9) and I want to have clean url.

If I enter for example "examle.com/example", this pops up an error "Internal Server Error" instead of showing the page.

What do I need to do to make this mistake disappear and show the page?

Dorcio
  • 1

3 Answers3

0

try this I hope its help you create a .htaccess file in your html folder and write blow code in it.

<IfModule mod_rewrite.c>
RewriteEngine On    
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
</IfModule>

or try below.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

and the last one is for trailing slash at the end. (only use codes as your needs only).

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
</IfModule>

more you can understand on

thanks.

dev_ramiz_1707
  • 671
  • 4
  • 20
0

That style of URL (domain.tld/resource/path) would need to be handled via mod_rewrite (with Apache) or a try_files configuration with Nginx. Which you use depends on which HTTP server you're running, of course. Unless you're explicitly setup Nginx, it's probably Apache.

Assuming Apache (httpd) is being used- The easiest method to manage this is via a .htaccess file in your document root (where your index.php file lives). You'll need to verify mod_rewrite is enabled in your httpd configuration (usually found at /etc/httpd/httpd.conf or broken out further in a subdirectory).

There are a lot of configuration options available to you via mod_rewrite. Here's an example of one that will translate all URLs that do not point to an actual directory or file (thus preserving your ability to serve static content directly from httpd) to index.php:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

You would need to parse the URL to determine what to do with it (it will be contained within $_SERVER['REQUEST_URI']. Be sure to reference the mod_rewrite documentation if you need to make changes to this configuration.

Bob Hensley
  • 459
  • 4
  • 11
0

I don't know why but all the time it shows me the error "500", even if I have empty .htaccess and basic files apache2.conf and 000-default.conf

Dorcio
  • 1