1

My website redirects to /temp when visiting the root, I'd like it to appear as the root, without the /temp in the URL address bar.

I have a simple .htaccess:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^$ /temp [L]

How do I make the address bar show www.example.com instead of www.example.com/temp?

Also, When I see the network panel, I notice the status code is 301, so is this equivalent to a redirect 301?

1

RewriteRule ^$ /temp [L]

If you have a physical directory temp in the root of your filesystem... and since you have omitted the slash from the end of the RewriteRule substitution then mod_dir will attempt to "fix" the request by appending a slash. It does this by issueing a 301 redirect. (You are then presumably relying on the DirectoryIndex to serve the appropriate file from that directory.)

You can resolve this by appending a slash to the end of the substitution, so mod_dir won't try and do this by issuing a redirect. For example:

RewriteRule ^$ /temp/ [L]

I notice the status code is 301, so is this equivalent to a redirect 301

Yes, that is a 301 (permanent) redirect.

  • That's all of my .htaccess. Unless the host(bluehost) has something on theirs – Wen Shenk Jul 18 '16 at 23:09
  • I tried it on my own linux server, the behavior is same: z.nycweb.io – Wen Shenk Jul 18 '16 at 23:13
  • I have not paid attention to RewriteRule for a while, so please forgive me. The OP is missing an R. I am not sure if R is assumed. Certainly, a 301 is the default if you do use an R. It seems to me that a R=302 might work better, however, you are the expert. However, if the OP intends to have the entire site run out of the temp directory, they can simply update the Apache .conf file even if it is temporary. Of course this requires a restart. Just my 1.736 centavos. – closetnoc Jul 18 '16 at 23:29
  • @WenShenk Ah... you've probably got a physical directory called "temp"? I've updated (redone) my answer! – MrWhite Jul 18 '16 at 23:33
  • 1
    That's right. Good answer, just a / was missing. Thanks! – Wen Shenk Jul 18 '16 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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