Denis
Denis

Reputation: 21

htaccess URL rewrite page.php?page

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:

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

Upvotes: 0

Views: 3188

Answers (1)

unm4sk
unm4sk

Reputation: 345

RewriteEngine On
RewriteRule ^pravila$  "/page.php?page=pravila"
RewriteRule ^onama$    "/page.php?page=onama"

Your Apache needs to be configured to Allow Override in this directory for .htaccess to work.

Upvotes: 0

Related Questions