RewriteRule on two directories

php .htaccess mod-rewrite url-rewriting

27 просмотра

1 ответ

38 Репутация автора

I'm trying to keep the user-end pages and the backend pages seperated by adding cms/ in front of the URL. My .htaccess file looks like this.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [NC]
RewriteRule ^cms/(.*)$ cms/index.php?url=$1 [NC]

My directory looks like this :

> Project
   > cms
   > pages

In my outer index.php I include al the pages in pages folder by the URL parameter url. Those will be for the user-end pages. I'm doing this because in that index page I also have the styling and navigation for all the pages. I want to do the same thing for the pages in the cms folder.

When I go to, it goes to the index page in the cms directory like it is supposed to. But when I go to, it goes to the outer index file and the url parameter in that file is cms/cms_page1. But what I want it to do is this: cms/index.php?url=cms_page1 so it opens the index.php in the cms directory and then includes the cms_page1 page.

Автор: Youness Arsalane Источник Размещён: 08.11.2017 11:46

Ответы (1)

0 плюса

140 Репутация автора

I'm not sure why this is happening. You should enable logging so you can see how URLs are being rewritten.

I suspect it has to do with the order of your rules, and that you're not stopping once certain rules match.

Try this:

RewriteRule ^cms/(.*)$ cms/index.php?url=$1 [L,NC]
RewriteRule ^(.*)$ index.php?url=$1 [NC]

Adding the L flag stops any other rules being applied.

Автор: nickstaroba Размещён: 14.11.2017 07:31
Вопросы из категории :