-1

I need help with my htaccess file. I added the following to remove all .php extensions which is working fine.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

However I have a directory /users which I want to rewrite the URL strings. The current URL is like this:

aero.site/maki/users/index.php?t=mf5cc

I want the URL to look like aero.site/maki/mf5cc

I used the following rewrite rule but it's giving me Object not found error:

RewriteRule ^([^/.]+)$ users/index.php?t=$1 [L]

My complete htaccess content is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L]

RewriteRule ^([^/.]+)$ users/index.php?t=$1 [L]

Kindly help me with the correct rewrite rule for the last line to turn aero.site/maki/users/index.php?t=mf5cc into aero.site/maki/mf5cc

FYI: my htaccess file is in aero.site/maki directory

devupp
  • 11
  • 6
  • `[^/.]` would match anything that is not a slash or a dot. `maki/mf5cc` does contain a slash. – misorude Feb 10 '20 at 08:14
  • Thanks @misorude. I tired to modify it to RewriteRule ^([^/]+)$ users/index?t=$1 [L], it's working but mf5cc is now showing mf5cc.php. What am I not doing right? – devupp Feb 10 '20 at 09:06
  • `[^/]+` matches `mf5cc`, so this gets rewritten to `users/index?t=mf5cc`. How can you expect it to show `mf5cc.php` now? – misorude Feb 10 '20 at 09:08
  • you misunderstood me. I mean it's actually showing mf5cc.php which isn't what I want. I simply want mf5cc – devupp Feb 10 '20 at 09:13
  • Well that’s because your other rule, that also matches `mf5cc`, gets applied first. It makes rather little sense, to try and use both of them at the same time like that. If anything, you should check if what was requested matches an existing file, if `.php` gets appended, and if so redirect there (https://stackoverflow.com/a/13225718/10283047) - and only redirect the rest to users/index.php – misorude Feb 10 '20 at 09:20
  • Okay, will try it. I hope I get it right because even the first result is affecting the /maki directory – devupp Feb 10 '20 at 09:44
  • I'm still unable to get it to work. Can someone help me please? – devupp Feb 10 '20 at 13:55

1 Answers1

0

I finally got it to work. Thanks to @misorude. Here's my updated .htaccess content:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


RewriteRule ^([^/.]+)$ users/index?t=$1 [L]
devupp
  • 11
  • 6