Wasnt sure what to put in the title to describe what is going on, but I was looking at ways I could deny direct access to files and folders. I added a line in .htaccess which didnt work so I removed it.
I have access to every page on my website, but index redirects me to the page I tried to prevent direct access to. I have deleted the content of .htaccess, index and the page im been redirected to, restarted wamp and used CTRL + F5 but nothing seem to work. No cookies are stored and no errors in inspect element.
This is my .htaccess file
Options -MultiViews +FollowSymlinks
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^http://example.com$ [NC]
#ERROR CODE -----------------------------------------------------------
ErrorDocument 400 /assets/error/400.php
ErrorDocument 401 /assets/error/401.php
ErrorDocument 403 /assets/error/403.php
ErrorDocument 404 /assets/error/404.php
ErrorDocument 500 /assets/error/500.php
RewriteRule ^400/?$ /assets/error/400.php [NC,L]
RewriteRule ^401/?$ /assets/error/401.php [NC,L]
RewriteRule ^403/?$ /assets/error/403.php [NC,L]
RewriteRule ^404/?$ /assets/error/404.php [NC,L]
RewriteRule ^500/?$ /assets/error/500.php [NC,L]
#User Pages-------------------------------------------------------
RewriteRule ^//?$ /index.php [NC,L]
RewriteRule ^signin/?$ /signin.php [NC,L]
RewriteRule ^signup/?$ /signup.php [NC,L]
RewriteRule ^signout/?$ /signout.php [NC,L]
RewriteRule ^forgot-password/?$ /forgot-password.php [NC,L]
RewriteRule ^credits/?$ /credits.php [NC,L]
RewriteRule ^leaderboard/?$ /leaderboard.php [NC,L]
RewriteRule ^updates/?$ /updates.php [NC,L]
RewriteRule ^live/?$ /live.php [NC,L]
#Misc--------------------------------------------------------------
RewriteRule ^misc/?$ /misc.php [NC,L]
RewriteRule ^maintenance/?$ /maintenance.php [NC,L]
#Maintenance-------------------------------------------------------
# files to load
# RewriteCond %{REQUEST_URI} !/assets/css/main.css$
# RewriteCond %{REQUEST_URI} !/assets/css/special.css$
# RewriteCond %{REQUEST_URI} !/maintenance.php$
# RewriteCond %{REQUEST_URI} !/.htaccess$
# here filter the developer's IP/
# RewriteCond %{REMOTE_HOST} !^212.251.187.11
# redirect page (maintenance page)
# RewriteRule $ /maintenance [R=302,L]
Edit
The problem seem to be occurring when I use example.com or example.com/, but not when using example.com/index.php.
There is only 1 .htaccess file been used and I've not made any changes to the apache files (atleast not my self), Im trying to find the .htaccess snippets I tried right before this started happening
I transfered my root folder to a different pc and everything works. I'm not sure what went wrong but I was not able to fix the problem. I'm reinstalling wamp to see if that solves the problem. I belive this is the code that I used before index stopped working Redirect 301 /old/file.html http://yourdomain.com/new/file.html I never replaced any of it with the index but with a 404 page and the page I was been redirected to.
The snippet was taken from:
http://viralpatel.net/blogs/21-very-useful-htaccess-tips-tricks/
Related
I'm at a bit of a loss. I'm working on a website so I have created a temporary construction.html page that I want to redirect all IPs to other than my own. Here is what my .htaccess looks like:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.org/$1 [R,L]
ErrorDocument 404 http://www.example.org/construction.html
Options +FollowSymlinks
RewriteCond %{REMOTE_ADDR} !^12\.34\.567\.891
RewriteCond %{REQUEST_URI} !/construction.html$ [NC]
RewriteRule .* /construction.html [R=302,L]
What's strange is that it seemed to work initially, but my IP still gets rejected most of the time, but I haven't found a pattern. Sometimes I can access the root index.html if I explicitly navigate to it.
What's even stranger is that if I comment out those last four lines, I still get redirected to the construction.html page.
I've made sure to clear the cache of the browser, and that doesn't seem to do anything. Perhaps it is a syntax thing? My understanding is that the changes should be instantaneous.
Based on your shown attempts, could you please try following. Please make sure that your index.html, consutuctions.html and .htaccess rules files are present in root folder. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymlinks
RewriteEngine On
##Block access to index.html here..
RewriteRule ^index\.html/?$ - [NC,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)/?$ https://www.example.org/$1 [NE,R=302,L]
RewriteCond %{REMOTE_ADDR} !^12\.34\.567\.891
RewriteCond %{REQUEST_URI} !/construction\.html/?$ [NC]
RewriteRule ^ /construction.html [R=302,L]
ErrorDocument 404 http://www.example.org/construction.html
On my cPanel account I have a htaccess file which looks like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)\.html$ $1.php [nc] //for rewrite all .php file with .html extension
RewriteRule ^$ /index.html [R=301,L] //for rewrite home page to url with index.html
RewriteRule ^/$ /index.html [R=301,L] //for rewrite home page to url with index.html
ErrorDocument 404 /404.html
Problem is: when i open link like:
https://www.domainname.tld/test ---> i have correct 404 error (page not exist)
https://www.domainname.tld/test.php or test.html ---> i have default 404 error of Apache
This is very strange...
I contact cPanel support and they say me that not is a cPanel error
Can you help me?
Problem was not with code inside htaccess but a config of cPanel! I disbale from WHM PHP-FM for interested domain (read here how to disable https://support.cpanel.net/hc/en-us/articles/360049690354-How-to-Disable-PHP-FPM) because staff of cPanel explain me that was error. (read here https://support.cpanel.net/hc/en-us/articles/360050895654-ErrorDocument-directive-not-being-honored-when-using-PHP-FPM-and-the-filename-provided-has-a-php-extension)
I would like to rewrite my URL only when typing this:
www.domain.com/dir1/dir2/dir3/
in that path there is a index.html file that will be automatically loaded. And I'd like it to become this:
www.domain.com/index.html
It is important that the root www.domain.com does not redirect to that subdirs because it already redirects to another .php file.
I wrote the following .htaccess file:
RewriteRule ^dir1/dir2/dir3/(.*)$ dir1/dir2/dir3/$1 [L]
but it redirects even when typing the root domain.com.
Could you help me with that?
Edit:
I have tried in another browser and the real problem is that when typing domain.com/dir1/dir2/dir3 or domain.com/dir1/dir2/dir3/index.html the dir1/dir2/dir3/ is still shown and is not hidden.
Edit 2:
my complete .htaccess:
AddHandler application/x-httpd-php56s .php
ErrorDocument 404 /404/404.html
ErrorDocument 500 /404/404.html
RewriteEngine on
RewriteBase /
Options -Indexes
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /404/404.html [R=404,NC,L]
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /404/404.html [R=500,NC,L]
Thanks
Replace your current code with this:
DirectorySlash On
RewriteEngine On
# skip all known resources from rewrite rules below
RewriteRule \.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ - [L,NC]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+dir1/dir2/dir3/(\S*) [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^(?!dir1/dir2/dir3/)(.*)$ dir1/dir2/dir3/$1 [L,NC]
we have a website in English. Now we want to have a translated copy of this website in German.
The index.html is located in the root folder: www.mydomain.com/index.html
Now I want to create a htaccess file which redirects all user which have set the preferred language in their browser to German (de, de-de, de-at, de-ch) to www.mydomain.com/de/index.html. All other user should be redirected to www.mydomain.com/en/index.html.
I tried a lot but I can't make it work. I do not really understand the regular expression thing and it's usage.
Most of the tries ended up with error 403 or 500. The current htaccess doesn't end up in an error, but it doesn't work.
The htaccess is now:
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^/(.*)$ /de/$1 [L]
RewriteRule ^/(.*)$ /en/$1 [L]
It seems like the file doesn't work at all. When I open www.mydomain.com it opens www.mydomain.com/index.html
Htaccess and rewriting works in general:
RewriteRule ^(.*)$ http://www.google.com/ [R=301,L]
works.
If I delete the slash behind ^
RewriteRule ^(.*)$ /en/$1 [L]
I get an error 500.
What do I do wrong?
I actually want the server to redirect to the webpage which the user tried to open. So if the user opens mydomain.com/index2.html he should be redirected to mydomain.com/xx/index2.html (and not to index.html)
Any ideas?
Thanks,
Jaroslaw
You can use this rule:
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteRule ^(en|de)/ - [L,NC]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^(.*)$ /de/$1 [L]
RewriteRule ^(.*)$ /en/$1 [L]
I want to be able to enter the following into the URL:
https://mydomain.com/fork
or
https://mydomain.com/fork/
And for both to goto a subfolder called
https://mydomain.com/prod/fork_contents/index.html
But still only display https://mydomain.com/fork (or https://mydomain.com/fork/, either way)
I would like index.html to act as the root so all the image urls, etc still work (they are relative to '/prod/fork_contents/')
Currently the .htaccess in the root is:
ErrorDocument 404 /live/site_documents/document404.html
ErrorDocument 403 /live/site_documents/accessDenied.html
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^fork$ /fork/index.html [L,QSA]
RewriteRule ^fork/$ /fork/index.html [L,QSA]
RewriteRule ^fork/(.*)$ /prod/forklift_contents/$1 [L,QSA]
https://mydomain.com/fork/ Works fine!
https://mydomain.com/fork Doesn't work. The index.html loads, but it can't find any of the files. Firebug's net panel reports the following 'https://mydomain.com/css/style.css not found'. So the second case (without the trailing /) doesn't seem to know to go into https://mydomain.com/fork/css/style.css.
Thoughts?
You can use the question mark for optional charters
RewriteRule ^fork\/? /prod/fork/$1 [L]
For a very good tutorial on rewriting check this website
.htaccess tips and tricks..