Let's say I have a domain called test.com.
Now my index.html is situated in /public_html/client/frontend/questionnaire/index.html, so I can access it in my browser via http://test.com/client/frontend/questionnaire/index.html.
What I want to achieve is:
* As soon as a user enters the url http://test.com, he or she should directly access the index.html
* Restrict the user so that he can only access this index.html file and not other directories on the server.
I think it should work somehow with the correct .htaccess configuration.
Any help would be great :)
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^$ client/frontend/questionnaire/index.html [L]
Here Options -Indexes is used to disable directory listing.
Related
I'm making a JavaScript web app running on an Apache 2 server. I'm wondering if it's possible (either with mod_rewrite or some other mod) to make any path you type load the index.html from the root path, but keeping the URL?
For example: "example.com/blah/blegh" will load "example.com/index.html", but the address bar will still have "example.com/blah/blegh". Same if you tried typing "example.com/everything/is/index" would still load "example.com/index.html" and have "example.com/everything/is/index" in the address bar.
A simple answer about any mods I would need to use and which commands might be best would suffice. Though a code example would be very useful since I'm new to regex's and Apache rewriting.
Thank you for your time :)
Note: I'm doing this since I'm using History.js to parse URLs/titles into the address bar and tab titles while navigating (a one-page dynamic site). I'd like to be able to just load up the root index.html with the user's initial URL request and respond to users' actions that way much like a REST server.
Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags
I'm trying to make URL's look better by using a RewriteRule in .htaccess, but it doesn't work.
This is the case. I have a root folder in which there is a PHP-file called pdf.php. The script in that file sends a PDF-file to the user, which name is given as a variable in the URL. The PDF-files are in a folder called pdf, placed in the root. That folder is protected so that it's only possible to get a PDF-file by using the script. All that for security reasons.
You can download the PDF-files when you go to http://example.com/pdf.php?file=pdf/File.pdf for instance, where pdf/File.pdf is the path to the PDF-file. That's working fine. I want it to work when you simply go to http://example.com/pdf/File.pdf, so that URL has to be rewritten to the one mentioned before.
I tried to make a RewriteRule using a generator, but it doesn't work.
The following rules are in the .htaccess-file in the folder pdf. Placing it in the root didn't work either.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^pdf/([^/]*)$ /pdf.php?file=pdf/$1
The protection of the folder pdf is as follows.
ErrorDocument 403 http://example.com/
Order deny,allow
Deny from all
Try this code in root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# to convert spaces to hyphens
RewriteRule "^(pdf)/(\S*) +(.*)$" /$1/$2-$3 [L,NE,R=302]
RewriteRule ^(pdf/.+)$ /pdf.php?file=$1 [L,QSA,B,NC]
I've been having trouble using .htaccess to redirect any path starting with a specific directory to a sub domain. The main issue may be the directory actually exists as it is what my sub domain points to. I am not concerned about maintaining the path, redirecting to the home page for each is fine. I also need this for several specific domains ie:
website.com/foo -> foo.website.com
website.com/foo/about.html -> foo.website.com
website.com/foo/other/index.html -> foo.website.com
website.com/bar -> foo.website.com
website.com/foo/about.html -> foo.website.com
website.com/foo/other/index.html -> foo.website.com
It looks like you want to Redirect a specific folder to a specific host. As an alternative to using mod_rewrite you could use mod_alias and RedirectMatch.
RedirectMatch ^/foo[$/]? http://foo.website.com/
RedirectMatch ^/bar[$/]? http://foo.website.com/
You could of course add more rules to fit your setup.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^foo\. [NC]
RewriteRule ^(foo|bar)(/.*)?$ http://foo.%{HTTP_HOST}/ [L,R=301,NC]
My site www.example.com has its document root to public_html directory. But, all of my content is hosted in public_html/www.example.com/. So, I want when a user visits my site he get contents from public_html/www.example.com/ and not public_html. So, what should be the .htaccess rewrite rule for that?
I am not good in rewrite rules but the best I found was:
RewriteRule !^blog blog%{REQUEST_URI}
There are two problems with this.
It will not work properly if user requested www.example.com/blog/
It will also not work when we use directory name as www.example.com
Give this a try and let me know if it works for you, and if it doesn't try to describe as detailed as possible what happens.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/www\.example\.com [NC]
RewriteRule ^(.*)$ /www.example.com/$1 [NC,L]
I'm using wordpress.
I'd like my site's domain root to display contents of another page while still showing my domain root as the url.
EXAMPLE: "http://www.mysite.com" displays contents of "http://www.mysite.com/blogs/home"
but users still see "http://www.mysite.com" in the address bar.
I've managed to get the redirect working, but it's not masking the URL. It essentially is redirecting.
Here's what I have now in my htaccess:
RewriteEngine on
RewriteRule ^\/?$ \/blogs\/home\/ [R,NC]
The R option forces an external redirect. Try just [NC] instead
what about this way.
put the index.php and .htaccess file in the root of your domain.
edit index.php to grab the "wp-blog-header.php" file from what ever location you put it. For example, if your wordpress file is located in blogs/home/ sub directory, you change the index.php file located in the root directory as require('./blogs/home/wp-blog-header.php').
forget about the redirect issue.
I think this is the easiest way. Or did I misunderstand your question?
There is a very simple solutions to this problem. In fact wordpress has an option to accomplish this task.
Go to Dashboard->Settings->Reading->Front page displays
Select a static page as front page.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^$ /blogs/home [NC,P]
PS: Make sure you have mod_proxy enabled in your Apache config.