Nicolas Roy
Nicolas Roy

Reputation: 3803

Url rewriting to page1/ and page1/page2/

I'm not sure the title of this post is quite clear...

I have 2 pages : page1.php and page2.php

I would like to have mysite.com/page1 show page1.php and mysite.com/page1/page2 show page2.php

It's the first time of my life I touch to .htaccess. I've added :

RewriteEngine On
RewriteRule    ^page1/?$    page1.php    [NC,L]
RewriteRule    ^page1/page2/?$    page2.php    [NC,L]

mysite.com/page1 works fine, but unfortunately mysite.com/page1/page2 shows page1.php (and not page2.php)... without the CSS.

What would you advice ?

Upvotes: 0

Views: 215

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

You can try your rules this way.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^page1/page2/?$ page2.php [NC,L]
RewriteRule ^page1/?$ page1.php [NC,L]

Upvotes: 1

Related Questions