user1097772
user1097772

Reputation: 3529

Problems with .htaccess with spaces

I have this .htaccess, it should hide .php, but it has probably problems with this url
www.webpage.com/index.php?msg=some msg with spaces
Could it be fixed?


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

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

EDIT:
www.mysite.com/message.php?msg=You%20are%20logged%20in%20your%20rid%20is:8
In page I just wrote the content of msg: $_GET["msg"]:

You are logged in your rid is:DOCTYPE htmlhtmlheadmeta charsetutf8 if IEscript srchttp:html5shiv.googlecode.comsvntrunkhtml5.jsscriptendiftitle ...


It wrotes the html document after, instead of rid which was passed there form session.

Upvotes: 0

Views: 314

Answers (2)

anubhava
anubhava

Reputation: 784878

You need NE (no escape) flag in your first rule:

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

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

Upvotes: 1

nerkn
nerkn

Reputation: 1982

use QSA = Query String Append.

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L, QSA]

Upvotes: 0

Related Questions