I am trying to run a index.html file automaticlly once clicking on the folder on the Website using .htaccess
code:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteRule ^$ /index.html [R,L]
and then i restarted apache and refreshed the website but the folder disappeared. i try to wrote the whole link in the Url then comes (Internal Server Error)
i have here centOS 7 as Operating system runing apache
thanks for helping me and excuse please my english :D
best regards
Jackob
Yeah it works (:
Adding the following to my httpd.conf (if you have access to it) is considered better form, causes less server overhead and has the exact same effect:
<Directory /myDirectory>
DirectoryIndex index.html
</Directory>
Related
I know there are a million posts about this, but I have read through a lot of them and made so many changes to get this to work, but I am at a loss. I have setup a redirect rule in my apache2 server web server, but it does not redirect.
My web server root folder structure:
/var/www/example/
|
|----l
|
|---index.php
|---.htaccess
/var/www/example/l/.htaccess content is:
$ cat /var/www/example/l/.htaccess
RewriteEngine On
RewriteRule ^l/([a-zA-Z0-9]{6})$ l/index.php?redirect=$1 [R=302,L]
I have also tried putting it in the root folder /var/www/example/.htaccess
My rewrite rule appears to be working correctly from this site:
https://htaccess.madewithlove.be?share=6cae684f-740d-4add-b711-53cdb5986681
mod_rewrite.so is installed and rewrite_module is loaded.
I ran sudo a2enmod rewrite and it was turned on
APache2.conf:
$ cat /etc/apache2/apache2.conf
<Directory "/var/www/example">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
When ever I go to https://example.com/l/i4Ikn2 I just get a 404 error.
I just want to know if I am missing something or somewhere to look. I checked the apache2 error.log and there are no error in there pertaining to this.
As #mrwhite and #anubhava mentioned in the comments below my OP, I was mixing up the way my .htaccess file was being used.
I removed the sub-directory flags (the l in the pattern) and added the QSA instead of the redirect (R=302).
This was because I was using the .htaccess file in the sub-directory.
The QSA was the correct 'option' for the redirect/rewrite (still unsure of the difference).
Original:
RewriteRule ^l/([a-zA-Z0-9]{6})$ l/index.php?redirect=$1 [R=302,L]
New (working):
RewriteRule ^([a-zA-Z0-9]{6})$ index.php?redirect=$1 [QSA,L]
I want to restrict access to a directory and all of its' sub-dirs and file using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)ht-test(.*)$ - [NC,R=401,L]
</IfModule>
It works fine on index.html but not test.php. I have not clue what's going on. Shouldn't ^(.*)ht-test(.*)$ match anything containing it in the URL? Tested it with this site and it seems to be mathing both php and html.
I also tried using <Directory "./ht-test"> Deny from All </Directory> but that gives me Internal Server Error no matter what I put in.
Here're my tests:
http://deepcorelabs.com/ht-test/index.html
http://deepcorelabs.com/ht-test/test.php
Finally, figured it out. There's a settings in Plesk for how PHP is served (under Hosting Settings for the domain)
I was using FPM application served by nginx which igonores .htaccess directives for PHP files.
Apparently, for performance reasons
After changing it to 'served by Apache' it worked as expected.
For some reason I thought disabling nginx proxy mode will disable it completely as service.
I have react app running on apache2.
In my app, there are 3 pages: home, about, register
I have 3 route like this:
<Route path="/home" component={....} />
<Route path="/about" component={.....} />
<Route path="/register" component={....} />
So, app works perfectly, when I go to www.onlyexampleurl.com, app is loaded correctly. I can list in home, about, register fine.
But, problem is, when I go directly to www.onlyexampleurl.com/about i am getting 404 from apache, because app is download from root path '/'.
How can I fix it? When I put www.onlyexampleurl.com/about to browser I want load about page from my app, but I am gettint 404 from apache.
Thank you for any help!
You need to redirect all requests to your entry file (assume it's index.html). Put in .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
This is standard solution for Single Page Apps.
This is a late response to the question, but I though I'd share what worked.for me, in case anyone bumps into the same problem.
This is assuming Ubuntu OS, I have not been successful for Linux:
I've followed certain steps from this post from Reddit and I can attest this works for making SPAs run in Apache web server with proper routing.
To quote:
1) In the apache2.conf located in etc/apache2/ I turned AllowOverride to All. I also added Servername localhost in the file. (I somehow skipped this last sentence, but still it worked fine in the end)
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
2) In the hosts.debian.tmpl file found in /etc/cloud/templates I added 127.0.0.1 <yourdomain.com> to the file where the other ips of the similiarity are.
127.0.0.1 yourdomain.com
3) I ran sudo a2enmod rewrite. Then I restarted the apache server via service apache2 restart. This turns on mod_rewrite.
Lastly inside of my project folder /var/www/html , along side my index.html file I created a .htaccess file and added in the following:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*$ / [L,QSA]
End quote
Assuming you've run npm run build and then copied all the contents inside the build folder to your public directory, this should work.
When I first started web dev, I wasn't really sure I made the VirtualHost config right, so what I usually did was first to make a dummy index.html with, say, Hello World example. When I've confirmed that I'm able to see Hello World in the browser (which means I got the VirtualHost config right), I dump the contents of the build folder to where the dummy index.html was.
Hope this helps you now as much as it did for me!
I am attempting to create an .htaccess file on an Apache server to implement 302 redirects. Hosting is provided by BlueHost.
Right now I am testing an .htaccess file which consists of just a single line:
Redirect http://mydomain.com/?_escaped_fragment_=about http://mydomain.com/about.html
The file doesn't work. After learning more, I created an httpd.conf file, which looks like this:
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
One of the answers to this question (Apache 302 Redirect) suggests the following may be at issue:
mod_alias is not loaded--how do I check whether it is or isn't?
Adding the httpd.conf file may require an Apache restart. Is this possible on a shared BlueHost server?
Any advice on getting the 302 redirects to work is much appreciated. Thank you!
You can't match against the query string in a redirect, you'll need to use mod_rewrite:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=about$
RewriteRule ^$ /about.html [L,R=302]
I was trying to setup Lithium Php framework. I followed the documentation for getting started.
I have done this: *"make sure mod_rewrite is enabled, and the AllowOverride directive is set to 'All' on the necessary directories involved. Be sure to restart the server before checking things."*
Rewrite module is enabled. Verified by
apache2ctl -M
I have changed the AllowOverride in /etc/apache2/sites-available/default file.
Now when I go to http://localhost/LithiumTestApp/, the page loads but sans css, js, images etc as the links do not work.
I can't seem to find what I have done wrong.
I'm running Apache2 on Ubuntu 11.10.
Edit: Contents of .htaccess are:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Part of Lithium Framework itself. I haven't changed anything here.
I'd recommend first checking to see if your rewrite is working properly.
I usually set a rewrite log path in my vhost file (or set it in your httpd.conf or apache2.conf, whichever your OS uses).
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 5
Then do:
tail -f /var/log/apache2/rewrite.log
That will allow you to see the log contents while it's happening and refresh the page and see if everything is in order. I also recommend having a look at your Apache error log to see if there are errors in the request.
Also, make sure your resources folder has write permission.