1

I have this .htaccess. file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

This rule work fine for a-z, A-Z, and 0-9, but I want that the rule matches every any Unicode character. I have tried This:

RewriteRule ^([A-Za-z0-9_-\s]+)/?([A-Za-z0-9_-\s]+)?/?([A-Za-z0-9_-\s]+)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

and This:

RewriteRule ^([\s\S]*)/?([\s\S]*)?/?([\s\S]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

but it doesn't seems to work. What am I doing wrong?

Community
  • 1
  • 1
Michael Haddad
  • 4,085
  • 7
  • 42
  • 82

1 Answers1

1

You can try:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/?([^/]*)?/?([^/]*)?/?$ index.php?controller=$1&action=$2&id=$3 [QSA,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Working perfect! Thank you very much my friend! – Michael Haddad Oct 28 '15 at 16:17
  • Hey @anubhave! Until now it worked perfectly, but suddenly I get an error. Until now I just used `$_GET["controller"]`, `$_GET["action"]`, `$_GET["id"]` without checking if it exists because the `.htaccess` set it in the first place. But suddenly it gives me an error: `Notice: Undefined index: id`. How can I fix it? – Michael Haddad Nov 08 '15 at 09:10
  • Not sure why but try: **`RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?controller=$1&action=$2&id=$3 [QSA,L]`** – anubhava Nov 08 '15 at 10:31
  • Still the same error. But when I delete the line RewriteCond %{REQUEST_FILENAME} !-d it works fine. – Michael Haddad Nov 08 '15 at 16:22
  • 1
    That mean your URL is a real directory in that case remove `RewriteCond %{REQUEST_FILENAME} !-d` line – anubhava Nov 08 '15 at 16:24
  • Works great. Thanks. But how could it be that it worked before and now it dosen't? Since I haven't change anything... – Michael Haddad Nov 08 '15 at 16:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94539/discussion-between-sipo-and-anubhava). – Michael Haddad Nov 08 '15 at 16:43