title: How to make RewriteRule work only if URL contains specific string?
body: <p>I need to add <code>RewriteRule</code> which works only if there is a certain string in the URL, otherwise I need to load the content from another folder. If the URL contains the string <code>test</code>, I need to send it to <code>index.php</code> as a parameter, else the content should be loaded from the <code>directory</code> folder.</p>
  
  <p>For example: The root folder of the project is <code>new_project</code>. If the URL is <code>http://localhost/new_project/test/something/</code>, then I need to send <code>test/something/</code> to <code>index.php</code> as parameter. Else if the URL is something like <code>http://localhost/new_project/something/</code>, then I need to load the content from <code>directory/something</code> folder.</p>
  
  <p>Following is the <code>.htaccess</code> file I've written so far:</p>
  
  <pre><code>Options +FollowSymLinks
  RewriteEngine on
  
  # Force Trailing Slash
  RewriteCond %{REQUEST_URI} /+[^\.]+$
  RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
  
  # Send request via index.php (again, not if its a real file or folder)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
  
  # Serve other requests from the directory/ folder
  RewriteRule ^(.*)$ directory/$1 [L]
  </code></pre>
  
  <p>What needs to be changed in the above <code>.htaccess</code> file so that the occurrence of <code>test</code> string in the URL passes the string after the string <code>test</code> along with the string <code>test</code> to <code>index.php</code> and if the URL doesn't contain the string <code>test</code> then loads the content from the <code>directory</code> folder?</p>