0

I have the following rule:

RewriteEngine On
Options +FollowSymlinks

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)(?:/([^/]+))?/?$ index.php?a=$1&b=$2 [QSA]

This rule redirect all requests to my index.php and works like a charm. Now I would like to ADD another rule that redirect all requests for the directory /admin/ to admin.php in root. (A request for www.mysite.de/admin/login should end in www.mysite.de/admin.php?a=login&b=) The second parameter b should be optional. How to reach this? Thx for any hint in advance.

hamburger
  • 1,339
  • 4
  • 20
  • 41

1 Answers1

0

You can test htaccess rules online (ex. here: htaccess.madewithlove.be)

This code works with: www.mysite.de/admin/login and www.mysite.de/admin/login/123

edited

RewriteEngine On
Options +FollowSymlinks

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^admin/?([^/]*)/?(.*)$ admin.php?a=$1&b=$2 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/?(.*)$ index.php?a=$1&b=$2 [NC,QSA,L]

#removed
#RewriteRule ^admin/([^/]+)(?:/([^/]+))?/?$ admin.php?a=$1&b=$2 [NC,QSA,L]
#RewriteRule ^([^/]+)(?:/([^/]+))?/?$ index.php?a=$1&b=$2 [QSA]

Notice that you need the L flag there. (RewriteRule Flags)

Also useful to see How L flags work - StackOverflow answer and Everything about mod rewrite - serverfault.com thread

verjas
  • 1,793
  • 1
  • 15
  • 18