.htaccesswhmcs

Rewriting this url for WHMCS using HTACCESS?


I have this url:

/index.php?m=mymodule&action=overview

I instead want this:

/mymodule/overview

Or even better, add another path prior:

/clientarea/mymodule/overview

Anyone know how to set up a rule in htaccess for this?

I had a look at how Drupal does something similar, but I don't think it helps my case. With drupal, you can open /bla/foo/whatever and it will effectively pass it as parameters to index.php. That is exactly what I am trying to do. So here's what drupal does:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

But that doesn't help me. I need something that specifically maps:

/mymodule/overview 

to

/index.php?m=mymodule&action=overview

Any ideas?

UPDATE

I am close with this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2index.php?m=$0&action=$1 [QSA,L]

If I access "/mymodule/overview" then query string parameter m = /mymodule/overview and not just mymodule. And action is blank. How do I =make it split "/mymodule/overview" into "mymodule" and "overview" ?


Solution

  • Only a helpful Answer!!

    #FROM /mymodule/overview 
    #TO /index.php?m=mymodule&action=overview
    #QAS QueryString Append
    
    RewriteEngine on
    RewriteBase /
    
    # Not Directory
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # Not file
    RewriteCond %{REQUEST_FILENAME} !-f
    
    # Not Link ?? No Need.
    #RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^((\w+)\/)((\w+)\/*)(.*)$ index.php?m=$2&action=$4&plah=$5 [QSA,L]
    

    TEST:

    mymodule/overview/do/some/thing --> match; plah=do/some/thing
    mymodule/overview/do/some/thing/ --> match; plah=do/some/thing/
    mymodule/overview/ --> match; plah is empty
    mymodule/overview --> match; plah is empty
    mymodule/ --> Not match
    mymodule  --> Not match
    

    I recommend to use a prefix m for example, for your modules; to prevent redirecting other URLs to your modules. /m/mymodule/overview Then use: ^m\/((\w+)\/)((\w+)\/*)(.*)$
    On Online Regular Expression Tester:
    https://regex101.com/r/TSvl9n/2