SK2017
SK2017

Reputation: 773

Get parameters from url with .php already removed

I have got my urls rewriting, removing .php and replacing with a /

currently the .htaccess looks like this -

RewriteEngine On


RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

although now, I am trying to pass a GET parameter,

When i add this to the .htaccess -

RewriteRule ^(.*)$ public_profile.php?params=$1 [NC]

or this

RewriteRule ^(.*)$ public_profile/params=$1 [NC]

And navigate to localhost/pages/public_profile/myparam

I get an internal server error.

I've also tried putting the .htaccess in side the pages/public_profile directory with

RewriteEngine On

RewriteRule ^(.*)$ index.php?params=$1 [NC]

And when I navigate to http://localhost/pages/public_profile/

and print $_GET , "index.php" is printed

Can any one point out what I am doing wrong?

Upvotes: 1

Views: 32

Answers (1)

anubhava
anubhava

Reputation: 785246

Have a separate rule for handling get parameter:

RewriteEngine On    

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?params=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

Upvotes: 1

Related Questions