In my website, I have a home HTML file. Then, when I click on something in the nav, for example Roster, the url changes to http://www.nextgengaming.org/Roster/roster.html. How can I stop this? I'm not so worried about the extension, as I can get rid of that later. Here is my file/folder setup that I use when building websites (please note that I have nothing in the html file for 'Roster', because I am focussing on the url right now):
Website
∟ Home
∟ CSS
HEADER (social icon images)
home_files (for my image slider)
IMG (the rest of my images)
home.html
home.js
∟ Roster
∟ roster.html
I will fill the roster with pretty much the same things. In my nav I have
<li>Roster</li>
so the URL is (as said before) http://www.nextgengaming.org/Roster/roster.html, and want to change it to
http://www.nextgengaming.org/Roster
OR
http://www.nextgengaming.org/roster.html
If you need any more information, please comment. Also, I'm not sure if this is the right place to post, but I'll take my chances.
The url changes to http://www.nextgengaming.org/Roster/roster.html How can I stop this?
The suggested ways would be to edit VirtualHost or .htaccess by adding
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
Note that rewrite module must be enabled (sudo a2enmod rewrite). Speaking of DirectoryIndex (documentation here) it searches for
index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml
And if none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory. Indexes may cause a security threat (exposing all the files) so use
Options -Indexes
to avoid that. If following the instructions, the
http://www.nextgengaming.org/Roster/roster.html
would be rewritten to
http://www.nextgengaming.org/Roster/roster
To avoid the Roster/roster and having just roster put the roster.html in your DocumentRoot probably right next home.html.
Simply use the default extensions (index.html usually), and change the URLs to: http://www.nextgengaming.org/Home and http://www.nextgengaming.org/Roster
The structure would be:
Website
∟ Home
∟ CSS
HEADER (social icon images)
home_files (for my image slider)
IMG (the rest of my images)
index.html
home.js
∟ Roster
∟ index.html
If you don't like renaming files like that, a more advanced approch would be to use URL rewriting (using .htaccess, for example).
Related
I have a situation as follows:
I have a website with lots of files in it (Yii Framework). I need to migrate it from http://domain1.com to http://domain2.com/foo/bar/
But previous developer has put the href, src, background-image etc links as follows:
href="/assets/img/img1.jpg"
src="/assets/js/script.js"
When I open the new website in browser, all the resources should be loaded like this http://domain2.com/foo/bar/assets/... to make it work. But, browser is interpreting the resources url as http://domain2.com/assets/...
As the resources doesn't exists here, they aren't loading.
As the urls are scattered everywhere in lots of files, it's not the best idea to change each and every url.
Is there a way to change the base url through htaccess (or some other method) so that server or browser will interpret href="/assets/..." as http://domain2.com/foo/bar/assets/...
You may use this 301 redirect rule at the top of other rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain1\.com$ [NC]
RewriteRule ^assets/.+ http://domain2.com/foo/bar%{REQUEST_URI} [L,NC,NE,R=301]
What do you guys think is the best way to link to other website pages of a website, in order to remove the .html extension visible in website URL?
Assume I have the following pages:
index.html
page1.html
page2.html
pagex.html
What is the best way to link to these pages?
page1
creating subfolders named "page1", "page2", and so on, with individual "index.html" files, and referral in the form of:
page1
Use page1 and set .htaccess to MultiViews
The best way is to divide your page up in sections you have an admin section? make a folder nameed admin and make your path as so admin/index.html so just every section on your page should have a folder and files inside that folder but i do not believe there is any guidelines to this so it is just my opionion
In your .htaccess file, use a rewrite directive:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) $1.html
This rule says: if the requested file does not exist, (internally) append an .html to it. That means the URL will show /page1, which will fit the RewriteCond, and internally the request will be treated as if /page1.html had been requested. That's the most straight forward way to map arbitrary URLs of your choice to arbitrary files on disk. Your links would then use the URL href="page1".
Also see Reference: mod_rewrite, URL rewriting and "pretty links" explained
Ok, maybe a pretty dumb question but I can't find an answer on Google.
I am coding my site by hand. How do I make the index.html disappear from the url's? Do I use a piece of code in my html? Do I have to change my href's in my files?
Hope you guys can help!
EDIT:
I've tried this with a .htaccess file
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
It does work, but all my links aren't working anymore. I discovered I had to remove all the index.html from the href's in my documents. But that would be a lot of work. Is there an other code for .htaccess that just hides index.html?
A SIMPLE WAY TO DO THIS in Html:
(example in my case is a simple dual language site)
If your link looks like this:
Homepage
You should change it to this:
Homepage
If trying to link to another folder in your directory, like is my example:
English language
You should change it to this:
English language
Notice that "/" goes back to your root directory and automatically selects index.html, so that is why I used "en" for the English language site, because the name of the folder in that case is "en". You should also make sure that you have index.html in your English language folder, and not index-en.html.
Apache has .htaccess files and mod_rewrite,
In your .htaccess file, set:
DirectoryIndex index.html
You can also set this up in the Apache site config files too
You can specify a list of filenames, so if it doesn't find the first it moves to the next.
IIS has .config files
mod_rewrite module is responsible for all the rewriteEngine. Check on your server whether is module is present and enable.
You need to create a file called '.htaccess' in the root directory of your site containing the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
And then make sure all the links on your site don't contain '.html' at the end, e.g.:
<a href="/Home.html">
should be replaced with:
<a href="/Home">
Hope this helps!
if you dont find .htaccess, you just need to create a new file using your text editor the same way you would any other html or css file, but save it as simply '.htaccess'
And save it into the root directory, so the same folder that you have your index.html file.
I think this is configured in IIS when you deploy the site, I'm not to sure on it but I'm sure you can specify a start point that your URL will use when you just enter the UL, that implies the Index.html page.
Sorry I'm not too helpful here, hopefully it will point you in the right direction.
Often these things such as Apache or IIS have this set up already, and it looks for the Index.html, Index.php first when you just put your URL in.
Great SEO idea! This is similar to nginx redirect loop, remove index.php from url and Apache .htaccess to hide both .php and .html extentions, as well as mod_rewrite not working htaccess — the idea here, for both Apache's mod_rewrite and nginx ngx_http_rewrite, depends on the differences between the external and internal URLs — in order for the redirect from /index.html to / work, yet not cause redirect loops when actually serving index.html, you gotta make sure you only issue the redirect for external index.html requests, but never for internal ones; this can only be accomplished by looking into the actual request_uri.
Here's the code for nginx ngx_mod_rewrite:
index index.html index.txt;
if ($request_uri ~ "^(.*/)index\.(html|txt)$") { return 301 $1; }
On Apache's mod_rewrite, it'll be something like the following:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/index\.html$
RewriteRule ^(.*/)index.html$ $1 [R,L]
Related:
nginx redirect loop, remove index.php from url
Apache .htaccess to hide both .php and .html extentions
mod_rewrite not working htaccess
References:
http://nginx.org/r/index
http://nginx.org/r/if
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteCond
Change the link that goes to your homepage to the website address.
You may have:
Link Here
Change that to:
Link
Or try this
Simply don't type the index.html in your browser and don't advertise it as such.
You can set the 'default document' on the web server (whichever you happen to be using) to serve 'index.html' in the absence of a file part. This way, someone going to http://www.mysite.com would be served http://www.mysite.com/index.html
I would like to link to pages inside my website, e.g:
Not: mywebsite.com/about.html But: mywebsite.com/about/
I've seen various websites doing this but it looks like they also react differently to things:
Apple.com:
apple.com/iphone/ works, apple.com/iphone/index.html works, apple.com/iphone redirects.
Opera.com:
opera.com/mobile/ redirects, opera.com/mobile works, opera.com/mobile.html does not work.
Mozilla.com:
mozilla.org/en-US/ works, mozilla.org/en-US redirects, mozilla.org/en-US/index.html does not work.
Which leads to another question: Are there different methods for this?
Edit:
It seems that Apple uses a folder for every page, e.g. a folder called 'iphone' with an index.html file inside it?
But Opera and Mozilla use something in the .htaccess file?
Removing Extensions
To remove the .php extension from a PHP file for example yoursite.com/wallpaper.php to yoursite.com/wallpaper you have to add the following code inside the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename:
RewriteRule ^([^\.]+)$ $1.html [NC,L]
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:
wallpaper
They are using .htaccess and URL rewriting. This is part of server configuration. You can not do it with html only.
This page explains basics of URL rewriting.
You folder then has to contain a file: index.*.
Like: /iphone/index.html, which can be /iphone/ as well
Or work with .htaccess
In the .htaccess file in your sites root folder just add the following line:
# ---- Render pages without urls
Options +MultiViews
The most upvoted answer doesn't check whether the URL points to a directory, so you're going to get some mysterious 'not found' errors when it tries to append '.html' to a directory path. Easily fixed:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]
The first condition will only pass if the path does not point to a valid directory. The second will only pass if the path points to a valid file when the .html extension is added. If both conditions pass, the rewrite rule simply adds ‘.html’ to the filename.
Notice that we can just match the entire path with .*. You can reject paths that contain a period character if you wish, but it's not really necessary since you've already checked that {REQUEST_FILENAME}.html is a valid file. In any case, it is unnecessary to escape a period character when it's inside a character class. I know you see this [^\.] everywhere, but the slash is redundant. [^.] is how to write it and look like a regex pro. 😎
This kind of redirect will be invisible to the user because, by default, mod_rewrite does the substitution internally, without informing the browser. If you wanted to do a permanent redirect, you would add the [R=301] flag at the end.
Alternatively, as Genus Amar said, you can just enable the Multiviews option on a per-directory basis by adding this Options Directive to the .htaccess file:
Options +MultiViews
It's worth adding that this will only work if the server administrator has enabled MultiViews with the AllowOverride Directive, and it won't allow you to perform additional redirects.
Neither of these solutions (on their own) will remove the .html if it’s part of the requested URL. If you want to do that as well, see my answer to this question.
Make your href attribute equal to the page you want to link or .. If you need to
move up a directory.
Ex: href="contact.html"
Ex: href="../links/contact.html"
I am hosting videos on my website.
In my code I link to the path of the video like this.
file: "video/some_random_video.mp4"
This works fine because the location of my .html page and the video folder is in the same directory.
Placing the videos here allows anybody to look at the .html source and find the path to where I keep all of my videos essentially allowing them to download them all.
Is it possible to place the videos back a few directories possibly in my root directory such that I can link to them but others cannot have access to them?
This is not working.
file: "./video/some_random_video.mp4"
I am trying to find any way to link to the videos on my server but disable users from checking the source and finding there location.
Any input is appreciated. Thanks!
To go backwards thru your directory, you need to use
file: "../../video/some_random_video.mp4"
(two dots, not one)
Optionally, you could try using .htaccess to prevent public access to your video folder
Try this:
"/video/some_random_video.mp4"
Assuming the video folder is in the root directory.
You can use root-relative urls like Kevin Boucher suggests.
Another option is to use an HTML base tag in the page head:
<base href='http://yoursite.com/'>
Then you can use links like this:
<a href='video/some_random_video.mp4'>Video</a>
In other words, it's as if all your links have your base href prepended.
As an aside, just remember that links in css files files are always relative to the location of the css file - irrespective of whether you use a base tag or not.
using .htaccess would be useful, many solutions exists.
try prevent hotlinking by checking the referer of requests.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example.com [NC]
RewriteRule \.(mp4|flv)$ - [F]
Take a look here or here
or passing the files through a PHP file and send them to the output while direct access to the files/folders is denied:
<FilesMatch "\.(mp4|flv)$">
Order Allow,Deny
Deny from all
</FilesMatch>