1

I have this url https://test.app/myapp/login. All I want is to remove the 'myapp' string using .htaccess. This is what I tried so far.

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]     

RewriteCond %{QUERY_STRING} ^(.*)&?myapp=([^&]+)&?(.*)$
RewriteRule ^(.*)$ /$1?%1%3 [R=301,L]

But its not working. Btw using codeigniter 4

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
unice
  • 2,655
  • 5
  • 43
  • 78
  • Thanks for sharing your efforts, so you mean you are hitting URL `https://test.app/myapp/login` and you want it be redirected it `https://test.app/` in browser? – RavinderSingh13 Aug 16 '23 at 05:39
  • I want it to be `https://test.app/login`, just like when your removing the index.php – unice Aug 16 '23 at 05:47

1 Answers1

2

With your shown samples please try following .htaccess rules. Please make sure to clear your cache before testing your URLs.

RewriteEngine ON

RewriteRule ^myapp/login/?$  /login [R=301,L,NC]

RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [L,QSA] 
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93