I use a .htaccess file to rewrite my urls to make them SEO friendly, this works fine.
This file is located in the root (public_html). A website runs there too.
Now I created a directory named 'templates' which is CHMOD to 777.
I want it to be protected so these files cannot be accessed from outside.
Through directadmin I protected that folder.
Now if I use my browser to surf on the website all the urls are still SEO friedly. However when I try to surf to that protected directory (templates) it shows a 404 page that I created but shows 401.shtml as title. If I look at the url it also shows 'domain.com/401.shtml/'.
It does not ask me for an username or password either.
Now if I delete or simply rename the htaccess file (to .htaccess2) which is located in public_html (the one that arranges all the SEO friendly urls) the pages on the website do not work (obviously) but now if I surf to that /templates directory, it does ask me for an username and password and I am able to login and access the files.
This is the htaccess file I use in the root:
RewriteEngine On
ErrorDocument 404 /home
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^(.*?)$ $1 [L]
RewriteRule ^(nl|NL|fr|FR|en|EN)/start\.html$ /$1/ [R=301]
RewriteRule ^([^/]*)$ /$1/ [R=301]
RewriteRule ^([^/]*)/$ index.php?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)$ /$1/$2/ [R=301]
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?page=$1&subpage=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /$1/$2/$3/ [R=301]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /index.php?page=$1&subpage=$2&subsubpage=$3 [L]
EDIT:
I've noticed that when I turn the RewriteEngine Off in the main htaccess file it does work too (except for the rewrite of course). Any idea's?
I found this on the web which seems to work!
The problem is that accessing protected content makes Apache send a 401 header.
I had to put the following in the .htaccess file which was located in the protected directory.
ErrorDocument 401 "Unauthorized Access"
RewriteEngine off
Related
I have a wordpress website physically located in the "wordpress" subfolder of the root folder of the website. I manage to hide the subfolder "wordpress" in the URL with the following code:
.htaccess on root folder
RewriteEngine On
RewriteBase /
RewriteRule ^$ wordpress/ [L]
RewriteRule ^(.*)$ wordpress/$1 [L]
.htaccess in wordpress subfolder
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
However, I have another website in another subfolder let's call it "other-wp" and this needs to remain as it is, with the URL pointing to:
https://mywebsite.com/other-wp/
Since I managed to hide the "wordpress" folder in the URL, I am unable to acces my "other-wp" it says the page doesn't exist.
I'm not skilled with coding for .htaccess so i don't know what i need to do to fix it.
Could you help?
You need to implement an exception for that second resource:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/other-wp
RewriteRule ^/?(.*)$ /wordpress/$1 [L]
I also made some other modifications to that top level configuration file, just smaller optimizations. In general you should check if you can place such global rules in the actual http server's host configuration. Using distributed configuration files (".htaccess") is just a fallback if you have no access to the real configuration. They work, but come with disadvantages.
My url looks like -
http://localhost/user_notes/?id=1234.
I want to be turn it into user friendly url like
http://localhost/user_notes/1234
My .htaccess file looks like -
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
RewriteRule ^(.+)$ /user_notes/?id=$1
</IfModule>
The problem is with RewriteRule ^(.+)$ /user_notes/?id=$1
For more info see my directory structure
Note : In my directory structure there is also a public folder. But I can access files without including public in URL through htaccess file (line 3).
Could you please place these rules at top of your htaccess file(I hope there are NO redirect rules for https in your htaccess file). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^ public%{REQUEST_URI} [L]
RewriteRule ^(user_notes)/(.*)/?$ $1/?id=$2 [NC,L]
I am working on a php redirect script which 302 redirects visitors to other sites when they access a redirect url..
The script gets a variable (id) from the url and then redirects the visitor to the specific page.
The url structure is : example.com/redirect/index.php?id=test
At the moment all redirects work if I use "ugly" urls, but I want to strip all unnessecary information out of the url with .htaccess rewrites for better usability.
Which .htaccess rewrite rules do I need to make the above shown urls look like : example.com/redirect/test
I am currently using the following .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
but they only work for urls like example.com/redirect/index.php?id=test if I try example.com/redirect/test I get a 404 error page.
It might be good to know, that I have 2 .htaccess files, one in my root directory and one in the root/redirects/ directory.
Best regards !
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)?/?([^/]+)?/?([^/]+)?/? [NC]
We're setting up a TYPO3 installation, and if the user calls example.com/ we'd like the server to redirect to /typo/index.php?id=106.
This should happen without a change in the address bar. Every other file access on the server (for example example.com/test.png) should be redirected to example.com/typo/test.png).
This is the .htaccess file in the root directory. As I understand, it will redirect everything which doesn't have /typo in the URL to the subfolder and attach the parameters:
RewriteCond %{REQUEST_URI} !^/typo/
RewriteRule ^(.*)$ typo/$1 [L]
Now, this already seems to work, when I call example.com/index.php?id=106 I'm not getting a 404. Unfortunately TYPO3 seems to have some trouble (or the .htaccess configuration isn't correct), because we get a message saying "No input file specified".
What's also missing is the initial redirect when no path is specified. It should then go to /typo/index.php?id=106.
You may try this in one .htaccess file in root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# URL with no path
RewriteCond %{REQUEST_URI} ^/?$ [NC]
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule .* /typo/index.php?id=106 [NC,L]
# URL with path
RewriteCond %{REQUEST_URI} !^/typo [NC]
RewriteRule ^(.+) /typo/$1 [NC,L]
Maps silently:
http://domain.com/ to
http://domain.com/typo/index.php?id=106
and
http://domain.com/anything
http://domain.com/typo/anything
For permanent redirection, replace [NC,L] with [R=301,NC,L]
I am trying to run a mod_rewrite rule to load the contents of index.php regardless of the entered URL.
Then in the index.php file I will deal with either returning a correct page or outputting a 404 page.
This is for SEO purposes to allow a nice URL like:
http://www.example.com/product
rather than
http://www.example.com/?p=product
I have this working on one sub folder of my blog but when trying to test it on a new project all i get is 500 errors as for ALL urls.
Here is the existing htaccess:
RewriteEngine on
RewriteBase /products/
RewriteCond %{HTTP_HOST} ^www.danclarkie.co.uk/products [NC]
RewriteRule ^(.*)$ http://danclarkie.co.uk/products/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !/admin.php$
RewriteRule .* index.php
Any help ^_^
Dan