Forum Moderators: phranque

Message Too Old, No Replies

url rewrite problem ?

         

PHPycho

5:13 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



hello forums !

CASE:
I want to have the url
1> http://example.com/admin -> admin/index.php?q=admin/login
(Note: if there is no any segment after admin it should be routed to admin/login)
2> http://example.com/admin/any -> admin/index.php?q=admin/any

And I performed the following for the url rewriting

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin/index.php?q=admin/$1 [QSA,L]

this is only working for 2> case
i would like to know how to handle for case 1> too ?
Any idea?
Thanks

[edited by: jdMorgan at 3:00 pm (utc) on Feb. 17, 2009]
[edit reason] example.com [/edit]

jdMorgan

3:00 pm on Feb 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see how this code corresponds to your stated requirements. Here is what it means:

# If requested URI-path does not resolve to an existing file on disk
RewriteCond %{REQUEST_FILENAME} !-f
# And if requested URI-path does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite any URL-path beginning with "admin/" and ending with <anything or nothing>
# to "admin/index.php?q=admin/<anything or nothing>"
RewriteRule ^admin\/(.*)$ admin/index.php?q=admin/$1 [QSA,L]

Your requirements seem to indicate that you need two rules, one requiring a requested URL-path of exactly "admin" and another requiring a requested URL-path starting with "admin", and ending with anything other than "/index.php" (this exception needed to prevent an 'infinite' rewriting loop).

Jim