title: htaccess URL rewrite page.php?page
body: <p>I need a solution for this. Need to rewrite two URLs:</p>
  
  <pre><code>/page.php?page=onama
  /page.php?page=pravila
  </code></pre>
  
  <p><strong>to</strong></p>
  
  <pre><code>/onama    
  /pravila
  </code></pre>
  
  <p>I tried many different solutions, and none of them are working. However, I did rewrite these URLs like I said, but then my page isn't opening so I guess it's all in the details.</p>
  
  <p>For the hint:</p>
  
  <ul>
  <li><p>page.php file is in root directory - it's full of if-else statements which includes other .php files from /pages/ directory into page.php file</p></li>
  <li><p>onama.php and pravila.php files are in /pages/ directory</p></li>
  </ul>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I guess I'm lucky :)
  Tried one more time with this and it worked, I'm not expert in .htaccess rules but this is the solution for mine problem:</p>
  
  <pre>
  
      RewriteCond %{QUERY_STRING} ^page=([^&\s]+)$
      RewriteRule ^(?:page\.php|)$ /%1? [R=301,L]
  
      RewriteCond %{QUERY_STRING} ^page=([^&\s]+)&page=([^&\s]+)$
      RewriteRule ^(?:page\.php|)$ /%1/%2? [R=301,L]
  
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([^\s\/]+)/?$ page.php?page=$1&r [L,QSA]
  
  </pre>
  
  <p><strong>EDIT (new problem)</strong></p>
  
  <p>I'm trying to make two rewrite rules and can't get them to working together.
  So, the problem is with RULE 1 and RULE 2.</p>
  
  <p>When RULE 1 is first in <code>.htaccess</code> file, it's working like a charm, but then I have a problem with RULE 2 - gives me a blank page.</p>
  
  <p>When RULE 2 is first in <code>.htaccess</code> file, RULE 1 doesn't work - gives me 404 page.</p>
  
  <p>In both cases, URL are SEF and working as it should, but the content isn't displayed.</p>
  
  <p><strong>My htaccess file:</strong></p>
  
  <pre><code># RULE 1 - rewriting "/index.php?view=X" to "/X" 
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^view=([^&amp;\s]+)$
  RewriteRule ^(?:index\.php|)$ /%1? [R=301,L]
  
  RewriteCond %{QUERY_STRING} ^view=([^&amp;\s]+)$
  RewriteRule ^(?:index\.php|)$ /%1/%2? [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^\s\/]+)/?$ index.php?view=$1&amp;r [L,QSA]
  
  # END OF RULE 1
  
  # RULE 2 - rewriting "page.php?page=X" to "/X"
  
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^page=([^&amp;\s]+)$
  RewriteRule ^(?:page\.php|)$ /%1? [R=301,L]
  
  RewriteCond %{QUERY_STRING} ^page=([^&amp;\s]+)&amp;page=([^&amp;\s]+)$
  RewriteRule ^(?:page\.php|)$ /%1/%2? [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^\s\/]+)/?$ page.php?page=$1&amp;r [L,QSA]
  
  # END OF RULE 2
  
  #RULE 3 - rewriting "index.php" to "/"
  
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
  RewriteCond %{REQUEST_URI} !/system/.* [NC]
  RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php/$1 [L]
  
  #END OF RULE 3
  </code></pre>