Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following in my htaccess:

#When your application folder isn't in the system folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?/$1 [L]

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

#Always redirect to SSL pages
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I want the www to be redirected and I want all pages to be https. It seems to work, but when I try to go to it redirects to

Where did that extra question mark come from?

In addition, creating a facebook like button seems to not like my domain at all. The button appears blank and I think its do with the above...?

Any help much appreciated.

share|improve this question
From the rules that have a question mark perhaps? – Ignacio Vazquez-Abrams Sep 9 '12 at 17:49
Is /hello an existing file or folder? – Ansgar Wiechers Sep 9 '12 at 22:52
up vote 1 down vote accepted

This is generally a poorly understood part of mod_rewrite. All rules (unless a rule is followed by [L]) are processed in order and the rules change the value of the URI. They do not change the value of %{THE_REQUEST}.

Hence your second rule:

RewriteRule ^(.*)$ ?/$1 [L]

Causes a request for /hello to be rewritten to ?/hello. The input to the next rule is now ?/hello.

The next rule:

RewriteRule ^(.*)$$1 [L,R=301]

Uses $1 to match the entire URI and sends a 301 redirect to that URI on a new domain. That's where the question mark comes from. It's an internal rewrite followed by a redirect in the same request.

You can solve this problem by moving the ^application rewrite and the valid file rewrite to the bottom, after all the redirect rules.

Your https redirect is missing [L,R=301].

I have no idea about Facebook like buttons but after fixing the question mark problem, if it still doesn't work, try asking again or reading though the Facebook documentation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.