htaccess smart url for listing directories - html

1> This is the htaccess rule to display a smart URL for the path /uploadr/public folder !!
/uploadr/public folder is the one to list the directories and does not contain any html documents or such
RewriteRule ^Uploadr-Public$ /uploadr/public [L]
However when i access http://localhost/Uploadr-Public in the url the path
mapping works fine but does not display the smart URL (Uploadr-Public)
How can is solve this ?
Heres the screenshot of what it is currently displaying in url!!
2> Also if suppose one wants to access a folder named temp which is in
/var/www/html/uploadr/public/temp
can he specify the path in url as
htttp://localhost/Uploadr-Public/temp
where Uploadr-Public/ is smart URL and temp is a folder inside public

Issue is that /uploadr/public points to a physical directory and you're not using trailing slash in rewritten path. mod_dir module that runs after mod_rewrite adds a trailing slash in front of directories.
You can use this rule to fix it:
RewriteRule ^Uploadr-Public/(.*)$ /uploadr/public/$1 [L,NC]
Make sure to clear browser cache before testing it.

Related

How to shorten my url using .htaccess file

My url:
www.example.com/about/about_me.html
I want it to look like this and open the about_me.html file
www.example.com/about
I want to search for my domain name followed by the /about and the page that opens is the about_me.html. I want to do this with my htacess file. And another thing is where i place my .htacess file in my server
This is made more complicated because /about maps to a physical directory on the filesystem. Ordinarily, mod_dir will append the trailing slash (with a 301 redirect) in order to "fix" the URL. To prevent this we need to disable this behaviour, however, there are potential caveats and security implications with doing this. If this is disabled, you may need to manually override this elsewhere on the system.
Try the following in the root .htaccess file:
# Disable directory listings (mod_autoindex)
Options -Indexes
# Prevent mod_dir appending the trailing slash
DirectorySlash Off
# Enable the rewrite engine (mod_rewrite)
RewriteEngine On
# Internally rewrite "/about" to "/about/about_me.html"
RewriteRule ^about$ about/about_me.html [L]
Now, a request for /about will serve /about/about_me.html. But a request for /about/ (with a trailing slash) will result in a 403 Forbidden (assuming there is no DirectoryIndex document in the /about subdirectory).
And requesting any other directory without a trailing slash (eg. /subdirectory) will also result in a 403 Forbidden, regardless of whether there is a DiretcoryIndex document present in that directory or not.
mod_autoindex needs to be disabled (ie. Options -Indexes) in order to prevent accidental information disclosure when DirectorySlash Off is set. See the relevant Apache manual page for DirectorySlash: https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash
To make life easier, avoid using URLs (without a trailing slash) that map directly to filesystem directories. For example, you could store all your content in a /content subdirectory, then the /about URL maps to /content/about/about_me.html instead. You then don't need to disable DirectorySlash (and it's trivial to block direct access to the /content if you need to).
For example:
# Enable the rewrite engine (mod_rewrite)
RewriteEngine On
# Internally rewrite "/about" to "/content/about/about_me.html"
RewriteRule ^about$ content/about/about_me.html [L]

Remove subfolder using URL rewriting

I'm not an expert of URL rewriting but I'd like to use .htaccess to show up a path like this:
https://www.example.com/folder/login/
in this way:
https://www.example.com/folder/
but I don't want a real redirect: my site should display https://www.example.com/folder/login/ page, but the URL would be different, so that an user could think that he still is on https://www.example.com/folder/ while logging in.
Is it possible?
If it is, one last question: I have already enabled RewriteEngine on on the ROOT folder, do I have to put it in another .htaccess file too (which is places into https://www.example.com/folder/login/)?
/folder/ is the requested URL and what appears in the browser's address bar and /folder/login/ is the underlying filesystem path that the request is rewritten to.
To internally rewrite /folder/ to /folder/login/ try the following in the root .htaccess file.
RewriteEngine On
RewriteRule ^folder/$ /folder/login/ [L]
/folder/login/ is presumably a filesystem directory, so this won't directly handle the request. Ideally, you would rewrite directly to the file that handles the request. In this case, I assume mod_dir will issue an internal subrequest for the directory index document, eg. index.php?
I have already enabled RewriteEngine on on the ROOT folder
Note that the order of directives matters.
do I have to put it in another .htaccess file too (which is places into https://www.example.com/folder/login/)
No, you can put it in the root .htaccess file. (You could put it in /folder/.htaccess, but the directives would need to change. It wouldn't make sense to put it in /folder/login/.htaccess since you then couldn't hide the /login subdirectory.)

htaccess - change part of requested URL before sending user onwards?

I have the following issue: we have an internal documentation system which generates help files as HTML. The software that generates them was recently upgraded and now there is a naming issue between capitalized and non capitalized folders.
Old URLs:
https://documentation.example.com/de/101/Skins/Default/Stylesheets/Components/Tablet.css
New URLs:
https://documentation.example.com/de/101/skins/default/stylesheets/components/tablet.css
We have different folders that are affected, so the URLs could look like this (there are many variations):
https://documentation.example.com/en/103/Skins/Default/Stylesheets/Components/Tablet.css
https://documentation.example.com/de/456/Skins/Default/Stylesheets/Components/Tablet.css
https://documentation.example.com/en/324/Skins/Default/Stylesheets/Components/Tablet.css
I would like to be able to take the requested URL, look for this string: "/Skins/Default/Stylesheets/Components/Tablet.css" change it to lowercase and then send the user on to the new changed URL.
Some of the solutions I have found require access to vhosts files which I don't. I am also unable to upload a PHP file or something like that.
Are there any solutions to my problem that could be done with the htaccess file alone? If yes how?
You need to define a rewrite map in your server/vhost config file where the css is hosted.
RewriteMap lc int:tolower
Then in your htaccess file, you can create a rule like:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [L,NC]
Let me know if you need anymore help. This htaccess rule will cause every url to be converted to lowercase. This is a generic htaccess you could make it more refined to search specifically for the URL you need.

htaccess: how to restrict IP Address for URL path?

(I don't think the above link provides an answer for this question; see comment below)
I'm using a CMS system that uses a database instead of the traditional file-directory structure to store/manage webpages. Since there's no folder for each webpage, I can't place an .htaccess file in specific folders to control access.
There is one .htaccess file that exists in the root directory. Is it possible to use that .htaccess file to restrict access by IP Address for a specific URL? If so, what's the syntax? Note, it must be for URL because I don't believe there is even a specific file with .html extension for a webpage with this CMS (it's all handled behind the scenes somehow).
For example, the .htaccess file is here:
/home/username/public_html/.htaccess
and the URL needing access control is here:
https://www.mycompany.com/locations/europe/contactus/
What's the code to place in the .htaccess file to only allow the IP Address of 111.222.333.444 (for example) access to the above URL?
If this isn't possible, is there another way to solve this problem for restricting IP Address to a specific webpage?
Using mod_rewrite to control access
Here is the documentation of it, you may go to section "Blocking of Robots" to block IP range which trying to access particular url.
I think you may try this, I am not sure whether is works, but still try it, hope it works for you.
RewriteEngine on # this is for opening the module
RewriteCond %{REMOTE_ADDR} =123\.45\.67\.[8-9]
RewriteRule ^/locations/europe/contactus/ - [F]

URL rewrite in html

I want to do URL rewrite in html pages.
Any help for that. every one knows about url rewrite but I found all article for pp, asp.net, classic asp. so please any one knows how to do url rewrite in html.
like wise I want to rewrite from
http://www.xyz.com/aboutus.html to http://www.xyz.com/About-us
Any help will appreciated.
Thank you.
I'm not normally huge on working with RewriteEngine, or .htacess, but according to this blog entry, you can use the following code to hide file extensions:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Just paste that in your .htaccess file, and put the changes to the server (upload the new .htaccess using an HTTP client). If your .htaccess already has RewriteEngine on, you should skip the first line.
If you want to change the URL from xyz.com/aboutus.html to xyz.com/About-Us, you also have to change the name of the file or folder aboutus to About-Us. Another possible solution would involve just having an index.html file in a folder named About-Us, which would make the server load that file automatically once a user accesses xyz.com/About-Us, and wouldn't display the filename.
To rewrite urls you need to configure the webserver to do that (for example in apache with .htaccess.
But if you want to do that without use server configuration, a bad solution exists: make a folder with the name of the url and put the html into that with the name index.php. For example about-us.html > about-us/index.html and in links put the url about-us. But is a bad solution.