URL does not work with slash after deleting extension using htaccess

I am working on localhost and my htaccess file

Options +FollowSymLinks Options -Indexes RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) $1.php [L] 

after adding htacces code url

 localhost/movies/news.php 

works

 localhost/movies/news 

also works but

 localhost/movies/news/ 

does not work. It shows "Internal Server Error". How to get to work with a slash and without a slash.

+6
source share
2 answers

Try this code:

 Options +FollowSymLinks -MultiViews RewriteEngine On # Internally forwards movies/news/ to movies/news.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.+?)/?$ $1.php [L] 
+2
source

The problem is that you are adding a slash, which you have news/.php , and this does not work.

The best solution is to rewrite the GET variable like this:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) index.php?url=$1 [L] 

Then you can filter the GET variable in the script and include the file or content that you need.

+1
source

Source: https://habr.com/ru/post/953312/


All Articles