V
V
Valery2013-01-06 17:05:27
Apache HTTP Server
Valery, 2013-01-06 17:05:27

How to compose RewriteCond for .htaccess?

Good Friday evening everyone.

Help compose a rewrite for htaccess so that a slash is added at the end if it is not there, but at the same time, for links like /url.json, it is no longer necessary to add it.

For example:

site.ru/any/url         >>    site.ru/any/url/
site.ru/any/url/        >>    site.ru/any/url/
site.ru/any/get.json    >>    site.ru/any/get.json


* Let me explain that the site.ru/any/get.json file may not really exist. The link only means that the answer will have to be in JSON

** I could easily do it in PHP ... but I want everything to solve its tasks.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
emailAlexander, 2013-01-06
@Akuma

Hello, try this
.htaccess:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(/|.json)$ [NC]
RewriteRule ^(.*)$ http://site.ru/$1/ [R=301,L]

Happy holidays!

H
Hungry_Hunter, 2013-01-06
@Hungry_Hunter

What if you try something like this? Specifying in the regular expression, what if there is a dot at the end and after it from 2 to 5 characters?
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !(/|.[a-zа-я]{2,5})$ [NC] RewriteRule ^(.*)$ http://site.ru/$1/ [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question