I need a solution for this. Need to rewrite two URLs:
/page.php?page=onama
/page.php?page=pravila
to
/onama
/pravila
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.
For the hint:
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
onama.php and pravila.php files are in /pages/ directory
EDIT:
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:
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]
EDIT (new problem)
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.
When RULE 1 is first in .htaccess
file, it's working like a charm, but then I have a problem with RULE 2 - gives me a blank page.
When RULE 2 is first in .htaccess
file, RULE 1 doesn't work - gives me 404 page.
In both cases, URL are SEF and working as it should, but the content isn't displayed.
My htaccess file:
# RULE 1 - rewriting "/index.php?view=X" to "/X"
RewriteEngine On
RewriteCond %{QUERY_STRING} ^view=([^&\s]+)$
RewriteRule ^(?:index\.php|)$ /%1? [R=301,L]
RewriteCond %{QUERY_STRING} ^view=([^&\s]+)$
RewriteRule ^(?:index\.php|)$ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\s\/]+)/?$ index.php?view=$1&r [L,QSA]
# END OF RULE 1
# RULE 2 - rewriting "page.php?page=X" to "/X"
RewriteEngine On
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]
# 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
/page.php?page=X
to/X
this means that whenever a user navigates to/page.php?page=X
the code in/X
is ran instead, maybe you need to to the opposite? Maybe you need a redirect? I'm not sure, however the rest of the question implies that there's nothing really in/X
and it's just an intended shorthand for something else. – apokryfos