M
M
MrKable2011-09-01 14:56:48
PHP
MrKable, 2011-09-01 14:56:48

Trailing slash and single entry point in PHP

I have a single entry point in my application - index.php. I used to achieve this with this line in htaccess -

RewriteRule ^(.*)$ /index.php [L]

Today I needed to make a trailing slash (when example.com/page/ opens instead of example.com/page). There is a suggestion to do so - But how to make these things work at the same time?

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


Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wott, 2011-09-01
@MrKable

they will work at the same time, only without a slash they will be redirected, and already with a slash they will be directed to index.php

K
Krio, 2011-09-01
@Krio

try pasting the following before "RewriteRule ^(.*)$ /index.php [L]"
RewriteCond %{REQUEST_FILENAME} !-d # если нет папки, то
RewriteCond %{REQUEST_FILENAME} !-f # если нет файла, то

M
Mikhail Osher, 2011-09-06
@miraage

Might help than
# Базовая настройка mod_rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Запрещаем обращения к файлам/папкам, начинающимся с точки.
RewriteRule "(^|/)\." - [F]
# Перманентное обрезание trailing slash
RewriteRule ^(.*)/$ $1 [R=301,L]
# Убираем www префикс, если SSL выключен (вроде сертификат привязывается к полному дому, не?)
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ %1%{REQUEST_URI} [R=301,L]
# Если не файл, не папка, не ссылка - принимаем все на index.php
# QSA - Query String Append - добавляем данные из QUERY_STRING
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteRule ^(.*)$ index.php [L,QSA]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question