skip to Main Content

I am trying to create a rewrite rule in my Apache .htaccess file and the goal is:
http://domain/folder/(any search string) to redirect to http://domain/folder/index.php?option=$1
example:
http://domain/folder/covid to redirect to http://domain/folder/index.php?option=covid

I got this setup in htacess in http://domain/folder, but somehow it’s not working:

RewriteEngine On
RewriteRule ^([^/folder]+)/([^/]+)$ http://domain/folder/index.php?option=$1 [L]

The website is hosted on http://domain/folder

Can someone help me on this?

2

Answers


  1. You could have your htaccess file like as follows. Please keep your htaccess file along side with your folder(named folder) and NOT inside folder.

    Please make sure you clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?option=$1 [L]
    


    OR in case your htaccess is present inside folder folder then try following.

    RewriteEngine ON
    RewriteBase /folder/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?option=$1 [L]
    
    Login or Signup to reply.
  2. You may try this .htaccess inside folder/:

    RewriteEngine On
    
    RewriteRule ^index.html?$ index.php [L,NC]
    
    RewriteRule ^index.php$ - [L,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .+ index.php?option=$0 [L,QSA]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search