I have the .htaccess in the main folder (/public_html) with the following lines in it. These are for an application i have installed on my domain.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
It seems like this rule makes every sub-folders inaccessible. For example i have a sub folder called /public_htm/public. I want this sub-folder and all of it's contents to be accessible to public. If i put a .htaccess file in this subfolder, what lines it needs to have to give access to it's content?
Replace your .htaccess with this code:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ app/webroot/$1 [L]
</IfModule>
Related
The problem: the presence of an identical URL to /page/, but with some file extension, i.e., /page.xml, results in a 404 for /page/.
So for example, my HTML sitemap, example.com/sitemap will 404 if example.com/sitemap.xml is present.
The .htaccess file of my Wordpress site contains rewrite conditionals that, as expected, appends a trailing slash to pages in the form of example.com/page so they are rewritten as example.com/page/.
.htaccess as follows:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
# 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
# BEGIN MainWP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/plugins/mainwp-child/(.*)$ /wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST [QSA,L]
</IfModule>
# END MainWP
So after some digging, I found the solution, which was to simply disable Multiviews in my .htaccess file, like so:
Options -MultiViews
I have a domain mudomain.com.ar and want to redirect all incoming traffic to mudomain.com
I've tried this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mudomain.com.ar$ [NC]
RewriteRule ^(.*)$ http://www.mudomain.com/$1 [R=301,L]
This rule redirects all traffic correctly. For example:
mudomain.com.ar/hello/ to mudomain.com/hello/
All traffic except traffic incoming to mudomain.com.ar/ar/
It seems like the .ar/ar/ in the domain is preventing the regex to work, but I can't understand why. Ideas?
Edit:
/ar/ contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And the webroot directory contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you're using Apache 2.4 then add this line after RewriteEngine On line in your site root .htaccess:
RewriteOptions InheritDownBefore
Read more about RewriteOptions
Below is the content of my .htaccess file on my site server.
# 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
I would like to block access to file requests in the folder notforyou (example of a request below):
http://my-cool-site.com/wp-content/uploads/notforyou/path/to/file.pdf
What rewrite conditions and rules can I add so that any file request from the folder like this can be redirected to another web page?
I added something like this at the top of the .htaccess but the files in notforyou can still be accessed:
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/notforyou/(.*)$ http://example.com/ [NC,R,L]
add below code into your .htaccess
RewriteEngine On RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|pdf|png)$ http://www.yoursite.com/hotlink.gif [R,L]
You’ll need to change you yoursite.com to your domain name, and change hotline.gif to an image file on your server that explains hotlinking is disabled on your site.
I am moving a website to wordpress and the site has hundreds of files available for download. The current file path may have a number of subfolders before the name of the file. Below are some examples of how a url may look.
"http://www.example.com/uploads/folder/subfolder/anothersubfolder/file.pdf"
"http://www.example.com/uploads/folder/file.pdf"
"http://www.example.com/uploads/folder/subfolder/anothersubfolder/anothersubfolder/file.doc"
I want to create a 301 redirect to handle any requests for these files and send them to the new url which would be
"http://www.example.com/wp-content/uploads/folder/subfolder"
I'm keeping the sub-folders the same in the uploads folder, so really I need a regex for pointing anything that goes to
"http://www.example.com/uploads/"
and point it to
"http://www.example.com/wp-content/uploads/"
Update
My current .htaccess file looks like
# 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
I've tried adding the answer from anubhava within the <IfModule mod_rewrite.c> block but I think there is an issue with the RewriteBase / from wordpress and me trying to add RewriteBase /uploads/. How can I have a rewrite condition for the /uploads directory?
You can use this redirect rule in DocumentRoot/.htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^uploads(.*)$ /wp-content/uploads/$1 [L,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I usually use this htaccess file to remove index.php from my URLs in ExpressionEngine
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
AcceptPathInfo On
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
# Looks for files and directories that do not exist
# and provide the segments to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
While that works great, before we move this site into production, we're directing all traffic to the given url to another via this htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]
My own ip address is replacing the localhost call so that I can access the site.
Basically what I'm looking for is a combination of these 2 that will remove index.php from my URLs for me but still redirect everyone else.
Thanks,
Steven
Found that this works great:
RewriteEngine on
# If your IP address matches any of these - then dont re-write
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anothersite.com/ [R=302,L]
# do not rewrite links to the assets and theme files
RewriteCond $1 !^(assets|themes|images)
# do not rewrite for php files in the document root, robots.txt etc
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]