I have a directory of .png images www.example.com/i/image.png which is located in /var/www/html/example.com/i/image.png
I however, also have some other .png images www.example.com/css/glyph/image.png which is located in /var/www/html/example.com/css/glyph/image.png
I would like to be able to access the images in the /i/ folder from the root directory.
Example www.example.com/image.png will actually take me to www.example.com/i/image.png
Does anyone have any kind of .htaccess solution that would allow me to do this?
Answers to this questions should help - Redirect with htaccess for images onto another server without redirect looping
Specifically:
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^.*\.(gif|jpg|png)$ http://imgserv.example.com/forums/$0 [L,R]
You can use this code in root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+\.png)$ /i/$1 [L,NC]
Related
I want to redirect HTTP to HTTPS in my .htaccess which is inside a subfolder which passes all the requests to my index.php file which is responsible for Routing.
But I is not getting redirected to HTTPS version of the website in my subfolder. I don't know what I'm doing wrong, my root .htaccess is configured properly but I'm confused about the subfolder .htaccess...
Everything works fine when HTTP in subfolder..
And also on root level it works fine too, I'm getting redirected to HTTPS but not when I go to the subfolder.
This is my root .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And this is my subfolder .htaccess:
# This will pass the requests to index.php
DirectoryIndex index.php
RewriteEngine on
RewriteBase /SomeFolder
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)https://$ index.php [QSA,L]
And also ZnVjayBTdGFja292ZXJmbG93
NoobWithGuns,
I think I can help you solve your problem but first I have a few questions.
1)Are you using virtual hosts? And if so, are there different virtual hosts (conf files) for each directory?
2)Is there an explicit reason why you are using https in the sub-directory and not the root? Or would you be able to use https all around?
I am a beginner web dev and I am attempting to convert one of my old wordpress sites into a vanilla JS/HTML and CSS website.
The URLs on my wordpress site began with www and had trailing slashes at the end of every url (other than the home page). I have been attempting different commands via the .htaccess file I created and I managed to successfully remove the .html extensions from my pages and add the www prefix. However, despite numerous tries (I have tried around twelve different snippets that I found on this website and others) I have not been able to add trailing slashes to the URLs.
I would appreciate any help. Thanks in advance.
The following is my current .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
I'm about to start building a site and I've set up an "Under Construction" site at http://positivechange.cl
I'd like to work directly on the root directory during development so that I don't have to move all files from a development subdirectory to the root directory, so I'd like to redirect users to something like http://positivechange.cl/maintenance
After searching online I know how to redirect to the subdirectory using RedirectMatch ^/$ /subdirectory/ on the .htaccess file, but that doesn't allow me to access the root directory and check how the site is going.
Is there any way to do this?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !(^|&)dev=1(&|$) [NC]
RewriteRule !^maintenance\.html$ maintenance.html [L,NC]
Key is use of query parameter dev=1. Without this query parameter site will show maintenance.html. But if you add ?dev=1 to your URL then you can access your development website.
Because you already using redirect...
try comment that line and tell me how it's goes.
Hope this helpful cheers~
I want to disbale hot linking of FLV and MP4 videos hosted on my server, except when the videos are displayed from a page which its URL starts with :
http://www.mywebsite.com/index.php?main_page=videos_page&
What are the apache configurations that I have to add to my .htaccess file?
To disable hot-linking and replace the content with a generic site logo fo sorts to direct people back to your site rather then the image, add this to the .htaccess folde rin the root of your site:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png\SOME FILETYPES NOT TO HOTLINK) [NC]
RewriteCond %{REQUEST_URI} !^/index.php?main_page=videos_page&
RewriteRule .*\.(gif|jpg|png)$ http://www.mywebsite.org/generic/imagetoreplace.png [NC]
Remember, .htaccess is hidden, so make sure 'show hidden files' it turned on in yoru ftp client.
Hey, I am trying to use mod_rewrite to make http://example.com/style/universal.css show the page http://example.com/style.php?n=universal
I am currently using the following RewriteRule:
RewriteRule ^style/([^/\.]+)\.css$ style.php?n=$1
But it doesn't seem to work, for some reason it instead shows a 404 Not Found which is not even the correct 404 page.
I have tried doing it without the extension .css (i.e. http://example.com/style/universal) with the RewriteRule
RewriteRule ^style/([^/\.]+)$ style.php?n=$1
Which works, but I would much prefer it if I could get it working with the .css extension.
It seems to be something with the server ignoring the RewriteRule if a file extension is used. Is there a RewriteCond or something obvious that I am missing?
I should also mention that there is a .htaccess in the parent directory which is set by WordPress, the contents of this are:
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help would really be appreciated.
Thanks in advance, Brad.
Set up your mod_rewrite to log all the steps it does processing your url
RewriteLog "/tmp/mysite_rewrite.log"
RewriteLogLevel 6
reading the logs you should be able to understand how your url is rewritten and what is the problem.