harrrrrrry
harrrrrrry

Reputation: 14477

How to check if REQUEST_URI is not empty in apache RewriteCond httpd.conf?

In Problem detecting empty REQUEST_URI with Apache mod_rewrite , its mentioned we can use

RewriteCond %{REQUEST_URI} ^.$

or

RewriteCond %{REQUEST_URI} "^/$"

I need to check if its not empty, then redirect it to an empty one(ignore all the string after HTTP_HOST).

I tried

RewriteCond %{REQUEST_URI} !"^/$"
RewriteRule .*  http://%{HTTP_HOST} [L,R=301]

but not work. It just caused an endless loop.

Also I tried RewriteCond %{REQUEST_URI} !^/$ also RewriteCond %{REQUEST_URI} !^\/$ also RewriteCond %{REQUEST_URI} "!^/$" also RewriteCond %{REQUEST_URI} "!^\/$"

Upvotes: 1

Views: 2925

Answers (1)

Brandon Harris
Brandon Harris

Reputation: 987

How about this:

RewriteRule ^/.+$ http://%{HTTP_HOST} [L,R=301]

Upvotes: 1

Related Questions