I wish to 301 redirect my conf file located at /etc/apache2/sites-available to a different folder on the server itself. But when I added:

Redirect 301 / /var/www/web/public_html

to the conf file and restarted Apache2 I see the URL as:


How can I 301 redirect to a folder and not a URL?

  • 2
    I wish to 301 redirect my conf file ... you clearly do not understand what a 301 redirect is. It only redirects HTTP requests based up on conditions. All files and folders must exist within the web space and be available to the web user. What you are trying to do in not possible. en.wikipedia.org/wiki/HTTP_301 Cheers!!
    – closetnoc
    Commented Aug 3, 2016 at 3:45
  • There was a wordpress module I used once, 404 to 301. I was hoping that it's possible to redirect all 404 to 301 Commented Aug 3, 2016 at 3:47
  • Your question appears to be clear, however, it is not. You cannot redirect a configuration file or any other file not within the web space. Can you clarify your question??
    – closetnoc
    Commented Aug 3, 2016 at 3:53
  • 1
    Apologies. I used to have a wordpress website with many posts. I removed the website and now have only a single landing page. However, I still have visits to the ghosts pages from the search engines. Instead of the visitors hitting a 404 or similar, I wish the visits to hit the page. But I want to do that without specifying the url, and instead specify the location where the page resides on the server itself. Commented Aug 3, 2016 at 4:05
  • 2
    Generally, redirecting all 404s to a single index page is a bad idea - for both search engines and users. It is better to provide the relevant information on a custom 404 page and include a link to your index page. Please update your question with relevant information from your comments. As closetnoc has pointed out, as it stands your question is not clear and is likely to be closed. I suspect you are wanting to write these directives in your Apache "conf" file (ie. the server config), not "301 redirect my conf file"?
    – MrWhite
    Commented Aug 3, 2016 at 10:48

1 Answer 1


While there is some overlap between the file system and the URL, that overlap only exists within the web space. /var/www/web/public_html is not within the web space. You cannot use this specification. You can only refer to anything within the public_html directory.

Taken what we discussed within the comments, use the code below in an .htaccess file within the public_html directory. Please know that any file with . and especially any file beginning with .ht will be hidden. You will have to have shell access (SSH) to your server.

> cd /var/www/web/public_html
> vi .htaccess

Of course you can use a control panel for this, however, I have no idea how to walk you through that.

Paste the following into your .htaccess file and save it.

RewriteCond %{REQUEST_URI} !^/index.html$ [NC]
RewriteRule .* /index.html [R,L]

Assuming that I got this right, the first line excludes any request not for /index.html and the second line takes those requests and redirects them to /index.html. In otherwords, if not /index.html then [show] /index.html.

If you want to see a listing of the files within your directory including hidden files, you can use:

> ls -al

In a control panel, there is an option to see hidden files within your file manager.

Of course this is only temporary until you figure out your website. Let us know how it goes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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