M
M
m1stik2018-09-29 17:24:47
Apache HTTP Server
m1stik, 2018-09-29 17:24:47

How to give access to a directory without a slash?

Hello.
You need to create a directory for api on the server, for the api itself, the request looks like this "site.com/api/data", but my address looks like this "site.com/api/data/". That is, I have index.php in the data folder, which is responsible for the directory, but the api cannot send a request for this file, showing the request status "301 Moved Permanently".
Help me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-09-29
@slo_nik

Try like this:

#
# Добавить слеш
#
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
#
# Удалить слеш
#
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]

D
dodo512, 2018-09-29
@dodo512

DirectorySlash Off

RewriteEngine On

RewriteRule ^api/data$ /api/data/index.php [L]

Add to the beginning of .htaccess in the root of the site

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question