Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL doesn't work with slash after removing extension using htaccess

I have been working on localhost, and my htaccess file is

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

after adding the htacces code,the url

localhost/movies/news.php

works

localhost/movies/news

also works but

localhost/movies/news/

doesn't work. It shows "Internal Server Error".How to make it work with slash and without slash.

like image 486
Prime Avatar asked Sep 06 '13 11:09

Prime


2 Answers

You an 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]
like image 169
anubhava Avatar answered Oct 20 '22 00:10

anubhava


The problem is when you add the slash you have news/.php and this is not working.

A better solution is to rewrite to a GET variable something 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 your script and include the file or content you need.

like image 20
René Höhle Avatar answered Oct 20 '22 01:10

René Höhle