Jump to content

adding trailing slash using htaccess


vishal.angre

Recommended Posts

Hello Guys,

 

I written code for adding trailing slash using htaccess. code as below.

 

RewriteEngine On
Options +FollowSymlinks

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$   /$1/ [L,R=301]

RewriteRule ^index/$ index.php

 

This code is perfectly working xamp local server. 

 

http://www.domain.com/index/      -  executes http://www.domain.com/index.php

 

But when i upload files on live linux server. it does not work. because index.php available on server like same name not work. If i make it.

 

RewriteRule ^home/$ index.php

 

then it will work on server.

 

http://www.domain.com/home/      -  executes http://www.domain.com/index.php

 

It means, the same file name exists then not work.

 

Please help on this. what is the problem. any rewrite condition to resolve this problem.

 

Link to comment
https://forums.phpfreaks.com/topic/275431-adding-trailing-slash-using-htaccess/
Share on other sites

So it worked? Great.

 

MultiViews allows you to omit extensions from existing files, so with it enabled /index will be automatically translated to index.php. By the time mod_rewrite and your RewriteRule kicks in, the request has already been "rewritten" to /index.php, the REQUEST_FILENAME !-f will not be true, and your URL rewriting will not trigger.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.