Madalin Alexandru
Madalin Alexandru

Reputation: 85

htaccess - access only if 2 dashes exist

My current rewrite rule to find users is this:

RewriteRule ^admin/users/(.*)-([0-9]+)$ /index.php?hook=admin&url=users&search=$1&page=$2 [NC]
RewriteRule ^admin/users/(.*)$ /index.php?hook=admin&url=users&search=$1 [NC]

I can find

@username test

@email [email protected]

@id 123

but when i'm searching by id /admin/users/@id-755, id is recognized as page

I thought to access first Rewrite only if contains 2 dashes, something like that

RewriteRule ^admin/users/(.*)([-{2}])([0-9]+)$

Anyone have an idea ? Thanks

@anubhava

so I can find by username, email or id

url.com/admin/users/@username-test

url.com/admin/users/@[email protected]

or

url.com/admin/users/@id-222 but here the id is recognized as page and we can have also pages like

                    ID-PAGE
                     | |

url.com/admin/users/@id-222-2 with page in url is working properly

Upvotes: 2

Views: 28

Answers (1)

anubhava
anubhava

Reputation: 785266

Have your rules like this:

RewriteEngine On

# don't execute further rules for real files/directories
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^admin/users/(.*?-.*?)-([0-9]+)/?$ /index.php?hook=admin&url=users&search=$1&page=$2 [NC,L,QSA]

RewriteRule ^admin/users/(.+)$ /index.php?hook=admin&url=users&search=$1 [NC,L,QSA]

Upvotes: 1

Related Questions