I have a site whose .htaccess file prevents incoming traffic except certain IP's, but now I need that the image directory can be accessed from any IP.
Here is the .htaccess file placed in the root:
Options +FollowSymLinks -MultiViews
order deny,allow
deny from all
allow from 87.221.15.139
allow from 127.0.0.1
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The directory allowed to be accessed from any IP is /wp-content/uploads/
How can I accomplish it?
You need to create an .htaccess file inside of /wp-content/uploads with the following.
Allow from all
Related
I'm struggling with the .htaccess file. I've wordpress installed in a subdirectory 'wordpress'. In the root folder if have the htaccess with the following content:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
Redirection is working, but how can I hide the subfolder 'wordpress'?
THX in advance
EDIT: Tried following content now but still not working:
root htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
wordpress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2: my whole root htaccess looks like this now:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
If i type in www.example.com I am redirected to example/wordpress/home, example/wordpress/contact and so on...
I would like to hide the wordpress directory like example/home, example/contact and so on
Redirection is working, but how can I hide the subfolder 'wordpress'?
You shouldn't be "redirecting". You should be internally rewriting the request instead. Remove the R flag.
For example:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
The slash prefix on the susbtitution string is also not required.
This assumes you have the standard WP .htaccess file in the /wordpress subdirectory.
UPDATE: Also confirm you have removed the /wordpress subdirectory from the "Website Address" and "Site Address" in WordPress General settings.
I have seen several other threads about this but for some reason in my specific case the solutions are not working.
Here is the .htaccess
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1
The desired effect is that index.php will load what ever page is requested in the GET (/events-diary = index.php?page=events-diary) & that works fine.
However I have some REAL directories which need to be accessible for example /admin/
The above .htaccess works perfectly fine as desired on my home computer MAMP, it works perfectly fine on my Amazon Micro, it will not work on the deployment server ipage.com
When you enter /admin it will redirect to the root index. When you type /admin/index.php it works, but you have to specify the index.php
I cant figure out when it seems to be ignoring the !-d
UPDATE:
index.php contains the following PHP
if(!isset($_GET['page'])){
header("Location: home");
exit;
}
$line=page_content($_GET['page']);
note that this functions fine on the other 2 servers, i dont see why it would behave differently on the 3rd.
Use:
Options +FollowSymLinks -MultiViews -Indexes
With -MultiViews with uppercase V.
For Apache, in some cases upper/lower case are very important
Here is a different set of rewrite rules that might work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [NC,L]
Are you trying to route things to /admin/index.php? If so, you could create a copy of your .htaccess, upload it to the /admin directory and set the RewriteBase to /admin.
or, if you wanted to turn the rewrite engine off in your /admin directory, you could create an .htacess file that contains:
RewriteEngine off
Difficult to post these suggestions in comment so resorting to an answer.
Try this rule:
ErrorDocument 404 default
ErrorDocument 403 default
DirectorySlash On
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
Now URL for my website is for example: http://localhost/xxx/index.php/welcome/
I want to change this to: http://localhost/xxx/welcome/
My .htaccess file:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
My config.php file:
$config['base_url'] = 'http://localhost/xxx/';
$config['index_page'] = '';
But my new URL still doesn't work. What should I add there?
You can try the following mod_rewrite. It actually works and I saw this on one of the tutorials I watched here and here is the .htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/foldernameifapplicable/foldernameifapplicable
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I do not recall all the changes made, but I followed the following tutorial and it did what you ask.
https://www.youtube.com/watch?v=I752ofYu7ag
htaccess looked like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
On my domain public directory is the laravel public directory.so there is index.php and htaccess file. but i want to access mydomain.com/demo/, where demo is a folder.its always redirect me to my home page as mydomain.com because of route rewrite . so how can i access folders in mydomain.com. my htaccess is followed. ...
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
thanks in advance
Create a separate .htaccess file within demo directory to override the .htaccess file in your root directory.
Order Allow,Deny
Allow from all
Create a separate .htaccess (as Brian Dillingham said) file within demo directory to override the .htaccess file in your root directory.
But put use codes below instead:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Also, you can refer the answer from: https://stackoverflow.com/a/38068912
For the ones out there who use a public domain but the Laravel directory is within a subdirectory. You might have the following folder structure:
- / <-- directory your domain (e.g. "https://example.com") points to
- some_subfolder1/
- some_subfolder2/
- laravel_project/
- ...
- public/
- .htaccess <-- File one has to modify
- index.php
- ...
The .htaccess File's RewriteRule for Front Controllers would look the following:
RewriteRule ^ laravel_project/public/index.php [L]
So you will end up with:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ laravel_project/public/index.php [L]
</IfModule>
In addition, I also modified the .env-File for the APP_URL param:
APP_URL=https://example.com/laravel_project/public
Furthermore, you might think of moving the laravel project files (despite from the public folder) outside of this file tree.
I have a website www.website.com and a few domains that redirect to this site. It's a masked redirect, so if I write www.domain.com I can see this url in the browser all the time, but it's actually redirected to subdomain.website.com What I'd like to do is do some .htaccess rewrite rule, so that everything that has domain domain.com will be rewrited to a local file on a server, that is outside of current folder. Let me explain folder structure here:
/
sub/
-- subdomain/
-- test/
---- index.html
web/
Currently everything from www.domain.com goes to /sub/subdomain. In the .htaccess file in /sub/subdomain I want to reroute the request to /sub/test/index.html. So in my .htaccess file in sub/subdomain folder I've tried this:
#start masked redirect
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} domain\.com$ [NC]
RewriteRule .. /test/index.html [L]
#end masked redirect
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Yes, I'm doing all this on top of Wordpress, which I don't really believe matters, but just to be sure I'm posting it.
Unfortunatelly I get Internal Server Error 500
What am I doing wrong, please?
Also: Please don't ask me why I am doing it like this, it has a reason, I'm not uncovering the whole thing I'm trying to do as it is irrelevant to this problem and I really want to focus on this issue here. I just want to know how to fix my .htaccess and it has to be this way. Thank you for your understanding.
This should be in sub/subdomain/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule !^test/index\.html$ /test/index.html [L,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress