Удалить index.php? Dir = из URL? - PullRequest
1 голос
/ 11 февраля 2012

У меня есть структура ссылок, такая как

http://www.example.com/folder/index.php?dir=
http://www.example.com/folder/index.php?dir=first/
http://www.example.com/folder/index.php?dir=first/second/

и т. Д.

Я хотел бы скрыть index.php?dir=, чтобы URL-адреса выглядели удобными для человека.

Пожалуйста, помогите мне настроить htaccess?

1 Ответ

1 голос
/ 11 февраля 2012

Это довольно простейшая настройка для .htaccess & mod_rewrite:

RewriteEngine On

# Don't rewrite if the file or directory actually exists
# protects against a rewrite loop if index.php is hit
# and allows css, js, images not to be messed with
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite everything to the dir=parameter, appending any existing querystring with QSA
RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]

Это должно включить URL, такие как

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...