hide image path possible with htaccess? - .htaccess

I got image path like that http://blablablabla.com/Admin/img/blablabla.jpg but i do not want to show this path user can i hide this URL with htaccess ?
For example : user will see path like that http://blablablabla.com/Info/img/blablabla.jpg but i have not Info folder this is possible ? so i do not want to see users never see my images paths is way is useful or not i'm not sure tell your ideas which way to most secure to hide my path

Rewriting your url will not make a difference security-wise. If the only security you have is hoping that no-one will ever know that a certain folder exists, then you have no security at all.
The requested rewrite can be done by placing the following directives in a .htaccess file in the www-root of your website.
RewriteEngine on
RewriteRule ^Info/img/([^/]+)$ Admin/img/$1 [L]
This is an internal rewrite that rewrites the url that is requested to an internal url that points to an actual file. $1 is replaced by the first capture group. See the documentation for more information.

Related

Hide directory where css, js, image folder are placed

I want to secure and hide my asset folder from publicity. I hear that can be done with the .htaccess file and change the name from my directory-name to random name of the directory and in that case, users can't know the real name of my directory placed into my public_html. Can someone help me with examples of all kinds of documentation? I didn't try anything because I have really bad knowledge of .htaccess coding. Any help will be thankful.
Well, you can do this, but I'm curious as to the purpose if it's just to casually "hide" the underlying file directory? This doesn't really offer any additional "security" and can also cause issues if you have a front-end proxy that is intended to serve static content. It can also be problematic if you are using a CMS like WordPress as you may need to modify the default behaviour. (Although there may be other developmental issues for which you would choose to do this.)
Ideally, you would do something like this with the Alias directive in the main server config (or vHost container).
In .htaccess you can internally rewrite the request using mod_rewrite. Lets's say you are referencing /assets in the URL, but the actual filesystem directory that this should map to is /secret then you could do the following to simply forward all requests to /secret:
RewriteEngine on
RewriteRule ^assets/(.+) secret/$1 [L]
Only requests for /assets/<something> will be forwarded. A request for /assets or /assets/ will simply result in a 404 (assuming this directory does not actually exist).
To be more selective and only forward requests for specific file types, based on the file extension, then you could do something like the following:
RewriteRule ^assets/(.+\.(?:jpg|webp|gif|css|js))$ secret/$1 [L]
You could also check to see whether the target file actually exists before rewriting, but this is generally unnecessary and best avoided since filesystem checks are relatively expensive.

Redirecting to a different directory with htaccess without changing URL

I would like to add some htaccess so that when a visitor goes to:
domain.com/xxx
They would see the content (without the URL changing) from
domain.com/yyy/zzz
Also any subcontent would show... like visiting
domain.com/xxx/inner-page
would show the content from:
domain.com/yyy/zzz/inner-page
I know that can be done, I just haven't figured out the htaccess code for it yet.
Here's the extra part I'm not sure can be done- sometimes those pages may have full URL links pointing to "/yyy/zzz/inner-page"
I would want anyone going to one of those pages to be redirected (changing the URL) to the equivalent "xxx" url... hopefully without causing a loop of too many redirects issue. Is that possible to do?
You may use this rule in site root .htaccess:
RewriteEngine On
RewriteRule ^xxx(/.*)?$ yyy/zzz$1 [L,NC]

HTACCESS: Redirect all the requests to another page, in place of index, hiding arguments?

I expose here my issue, I hope to explain myself clearly and correctly. In case of any specification, please ask me.
What I need is to redirect all the request (except the one to index.php) to another .php file, without the necessity to specify an argument.
here an example of what I need to do:
http://www.example.com -> shows index.php
but:
http://www.example.com/songs/title-of-the-song
should call the page: songs.php?dir=title-of-the-song of course without showin to the user the string "songs.php?dir=title-of-the-song" but just the URL
http://www.example.com/songs/title-of-the-song
It's what occurs with Drupal, but i'm not using that CMS for my site.
You are probably looking for something like that:
RewriteEngine on
RewriteRule ^/songs/(.+)$ /songs.php?dir=$1 [L]
Note: this is the version for the http host configuration. For usage in .htaccess style files you have to adapt it slightly. But if you have access to the host configuration you should always prefer that over .htaccess style files. Those files require an additional module, are notoriously error prone, hard to troubleshoot and really slow the server down.

URL rewrite rule in the same file (using anchor-lists)

I´ve just made a website based upon an only index.html file. You can surf the file using the menu that is made of anchored lists. The problem is that the URL is the name of the anchor, so I have two options:
1.- Rename the whole anchored lists (but there would be still some problems)
2.- Rename the URL using .htaccess, doing RewriteEngine On.
The URL you can see when access to the homepage is:
http://domain.com/#!/page_home
Notice: Only 'domain.com' is not real.
And next 'pages' are then:
http://domain.com/#!/page_2
http://domain.com/#!/page_3
http://domain.com/#!/page_4 and so on...
And I want to be displayed http://domain.com/welcome instead http://domain.com/#!/page_home.
Well, I´ve follow some basic and advanced tutorials with no luck. In theory using something like this should work:
RewriteEngine On
RewriteRule ^#!/page_home welcome
But this and others combinations didn´t work for me.
.htaccess is working because I have another rules like this one:
Options -Indexes
ErrorDocument 404 /notfound.html
Can you give me a hint please?
Thanks in advance.
I'm sorry to tell you this, but it won't work.
As you know already, anchor is a link to an internal resource in a web page. When you click on an anchor, no request is sent to the server, only the browser goes to the requested resource in the same page. If no request is sent to the server, then no htaccess is called and no redirections are made.
Your only option if you want the links to be like that is to redo the website without using anchors ...

Rewrite all requests from a single directory to a script - .htaccess

I need change files url in one folder in my server. It should prevent from direct download but I don't need deny from all rule.
Example:
typical direct link:
http://www.domain.com/foder1/folder2/file.ext
and I need this:
http://www.domain.com/page.html?file=foder1/folder2/file.ext
so in my case I need add this string (page.html?file=) to url. Maybe I'm wrong But I think it must be redirect becouse rewrite not execute page.html just only change (view of) url.
To do this, you need to use mode_rewrite. It will execute the page.html file just fine. It just won't update the URL in the browser bar. So, the user will have no idea they have been directed from the actual file to a script/html page. (As they probably should not!)
Here is an example:
RewriteEngine On
RewriteRule !^foder1/folder2(/|$) page.html?file=%{REQUEST_URI} [L]

Resources