Webpage link ends in a slash - how can i remove that? - html

I'm currently hosting my files on a local server while i build my site. I have my files organised in a way such as this:
images
image1.jpg
image2.jpg
about
index.html
I want the index.html file to be mywebsite.com/about, but when I click the link to it, it goes to mywebsite.com/about/, with a slash on the end like so. How can I get rid of the last slash? Am i organising my files incorrectly?

That is the way it is supposed to work. You are referencing the directory, not a file. When you enter http://mywebsite.com/about, the web server looks for a file called "about" in the root. If it doesn't find it, it looks for a folder called "about." If it finds one, the URL will always end in a slash.
If you really want to have the url end without a slash, you'll need to do one of the following things:
Create a file called "about" in the root directory (that your web server knows to handle with the correct handler and mimetype)
Use an .htaccess file to rewrite the url, something like:
RewriteRule ^(.*)/$ $1 [R=301,L]

You can add the following to your .htacces file:
# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
I hope this helps.

Related

How can I redirect to different file extension via htaccess

How can I redirect all the visitors to a different file extension. Example:
Visitor trying to access: http://www.anywebsite.com/0001.jpeg but redirect to http://www.anywebsite.com/0001.pdf. There are thousands of files in one directory with such redirect. How can i redirect all files using a single code in .htaccess ??
This maybe a possible duplicate question but you can find it easily via search
# change file extensions
RewriteEngine on
RewriteRule ^(.*).jpeg$ http://domain.tld/$1.pdf [R=301,L]
Review this link for further explanation:
https://htaccessbook.com/add-remove-change-file-extensions-htaccess/

what kind of attribute does '#' represent in Mac OS

I'm using nginx to build a web server. By default, there is a folder named html, which contains an index.html and a 50.html. If we visit localhost, the index.html in the folder html will be shown.
Now I need to create my own folder containing all of my .html files. But when I configure nginx and try to visit them, I always get an 403 error.
For now I'm considering it's the problem of attributes of .html files.
I've found that the attributes of html folder contain an #, whereas my folder doesn't. I want to know what does it mean and how to add such an attribute for my own folder.
The # signifies that the file has extended permissions attributes beyond the standard U/G/O. It could be related to metadata or quarantine functionality. You can view the attributes by using the xattr command:
xattr file.jpg
You can remove the extended attributes like so:
xattr -d file.jpg
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/xattr.1.html

Convert English URL to Spanish URL

I need to convert English URL to Spanish URL. I have tried URL re-write management, but that does not help me.
Following URL will show how to do URL re-write.
http://blog.beetleweb.com/2012/10/creating-custom-magento-url-rewrites/
My objective is to convert
URL
www.example.com/customer/account/create
to
www.example.com/cliente/cuenta/crear
Do I have to create a new store for this, or this can be done without creating a store?
Magento solution:
(the code below is not tested, it's just a beginning way of resolution)
Create a custom module for rewrite Magento customer URL.
In your app/local/MyNameSpace/MyModule/etc/config.xml, you can have
something like this :
<frontend>
<routers>
<customer>
<use>standard</use>
<args>
<mynamespace_mymodule before="Mage_Customer">MyNameSpace_MyModule</mynamespace_mymodule>
<frontName>cliente</frontName>
</args>
</customer>
</routers>
<frontend>
Apache2 solution :
(the code below is not tested, it's just a beginning way of resolution)
Use Apache2 rewrite url rules, in .htaccess file in root directory for example.
Your .htaccess file seems like something like this :
RewriteEngine on
RewriteRule ^/customer/([a-z0-9\-]+)$ /cliente/$1 [L]

preventing all subdirectory listing by redirecting

I want to prevent all subdirectory listings and redirect to index page instead.
Folder structure is the following:
/images
/images/folder1
/images/folder2
/images/folder3
/images/folder4
etc.
The number of folders is not predefined. I want to place .htaccess file in /images folder to provent /images/folder1, /images/folder2 etc. listing in browser.
I have not found the sollution. I have just found how to prevent listing using
Options -Indexes,
but no idea how to redirect to homepage (for all subfolders).
When it was predefined number of folders, I simply put index.html with redirection inside those, but now the number of folders is dynamic.
EDIT:
I have already looked into google searching something like "RewriteRule example redirect all subfoldres to homepage" and similar.
For example:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1.*$ http://example.com/folder2/ [R=301,L]
However, I have not found the solution with dynamic folder (if I do not know the exact name of folder, but I need to take all subfolders).
As I am new to htaccess writing it seems tricky for me.
I believe this should work for you in images/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.+$ / [R=301,L]
It redirect every request from images folder which is for any directory but not for a file to your home page /
Modify your .htaccess file to prevent indexing like this:
Options -Indexes
The folders won't be shown.

HTML local file access

I would like to access a local file in the immediate directory
From my understanding, you'd usually have to do something like
file://path/to/file/document.html
which requires the full path, but I would like to do something like
file://./document.html
instead, where ./ represents the current directory reference, so that I do not have to know the directory path nor make any assumptions about it.
is there any trickery like that possible with html file paths?
Use:
document.html
With no protocol specified, and no / for directories, the browser should request the asset from the same directory/folder that the current page is at.
If it's running locally (from that directory), just use ./ without the file://.
try this http://www.nt22.com/html_tutorials/022_html_path.html
using page.html and ./page.html works the same.
../ goes to a lower directory
i.e.
root/www/page.html
if you are in root/stuff/hi.html you can go to the 'www' directory by doing
../www/page.html