Kamil Zachradnik
Kamil Zachradnik

Reputation: 31

how to rewrite GET param using htaccess

I need to rewrite the url:

https://pieskowato.pl/posts.php?post=param

to

https://pieskowato.pl/posts/param

i found the htaccess config and it works at localhost but not in production..

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]
RewriteRule ^/post/([^/]*)$ /post.php?post=$1 [L]

url https://pieskowato.pl/post/dlaczego-warto-adoptowac-psa

Hosting OVH.com

Upvotes: 2

Views: 68

Answers (2)

anubhava
anubhava

Reputation: 786291

Have it this way:

# important to turn off MultiViews
Options -MultiViews
RewriteEngine On

# fix css/js/images
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]

# handle /post/anything
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([^/]+)/?$ post.php?post=$1 [L,QSA,NC]

Upvotes: 1

RavinderSingh13
RavinderSingh13

Reputation: 133770

With your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^[^/]+/([^.]+\.(?:js|css|jpe?g|png|gif))$ /$1 [L,R=301,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^(post)/([^/]*)$ /$1.php?post=$2 [NC,L]

Upvotes: 1

Related Questions