views:

287

answers:

2
Options +FollowSymlinks
RewriteEngine On
RewriteBase /mysite

RewriteRule ^([^/\.]+)/([^/\.]+)/?$ page.php?p=$1&name=$2 [NC,L]
RewriteRule ^([^/\.]+)/?$ page.php?name=$1 [NC,L]

The above code is written in my .htaccess file. I want my URL from:

http://localhost/mysite/page.php?p=categoryname&name=article_title
http://localhost/mysite/page.php?&name=articel_title

to:

http://localhost/mysite/category/article_title
http://localhost/mysite/article_title

Those rules are working fine but if I try to access my back-end for the admin which URL is http://localhost/mysite/admin` it redirects the page to page.php?name=admin. Is there a way to just limit the rule only for the page.php and not affecting the other pages under sub-folder which is admin?

+1  A: 

You could use a rule to stop /admin from beein rewritten:

RewriteRule ^admin$ - [L]

Put that rule before the others and it will be the only rule that is applied to /admin.

Gumbo
A: 

If you add this rewrite condition before your rules, it will only apply the rules if the request is not for a real file.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ page.php?p=$1&name=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/\.]+)/?$ page.php?name=$1 [NC,L]
bmb