I am currently trying to get to grips with .htaccess.
On my website, my about.html page (which is just a basic text HTML page) works fine with what I have managed so far:
mywebsite.com/about.html
works and shows as:
mywebsite.com/about
I have another section called:
mywebsite.com/works/
Which is full of .jpg and .html files and several folders. I currently have:
mywebsite.com/works.html
working which opens up that page and displays all my works as thumbnail .html links which can be clicked and accessed.
I want the website to display this page as:
mywebsite.com/works
instead of:
mywebsite.com/works.html
I don't have any issues with my about.html page because it is just one HTML page, but as works is a folder, when I type:
mywebsite.com/works.html
it shows up as it should but when I remove the .html I get:
mywebsite.com/works/
As a Fancy Directory listing!
How can I simply change this so that it just shows up as:
mywebsite.com/works
Create like this
works/index.html
And try to access like
www.example.com/works/
you can put a copy of works.html with name of index.html this can solve your purpose.
you can also restrict listing by adding
'Options -Indexes' in your .htaccess.
Gumbo's answer in the Stack Overflow question How to hide the .html extension with Apache mod_rewrite should work fine.
This should also work in a sub-directory path:
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]
Related
I am designing a portfolio site for a client. I am using Semplice template for Wordpress as it is supposed to be a good theme, but the thing is that is not so customizable as I would like, so I've designed the home page with HTML, CSS and JS on my own, with no templates. So I want to use the index.html I've created only for the home page, and Wordpress+Semplices for the rest of the sections of the website.
Now, I've already uploaded the Wordpress content and database to the host, and it's working. I am uploading my HTML+CSS+JS through the CPanel, but I here comes the problem:
I can upload my files to the root directory of the Wordpress in the public_html folder. If I do it, It keeps using the index.php (which charges the wordpress index, that I don't want), unless I delete this file and leave only the index.html that I've designed, in which case it runs my index but it doesn't loads the rest of the Wordpress even if I write the links to the sections properly. So it looks like this default index.php charges the rest of my wordpress them, and if I delete it, it won'g load anymore.
So, to conclude, I need something that charges both of them, the index.php which will load the rest of the wordpress sections (work, about me, info, etc.) but that uses my index.html as the default home that appears when I write the URL in the browser.
I will show you the files of my public_html folder, just in case it can clarify something for you to help me and understand me better:
By the way, as you can see in the image, I have no .htaccess file in my folder. That's confusing. What's the reason?
The .htaccess file can be not visible, try unhiding it in your File Manager -> Settings -> Show hidden files. If it's still not there, you can create .htaccess file yourself.
After that, it should be an easy redirection with the .htaccess file as this:
RewriteRule ^$ http://example.com/path-to-html.html [L,R=301]
On a website I have a directory service-name which I don't want people to have access to, since it just stores css files, images and pdfs. Further more, in a different folder on the site, at the web root, there is a page service-name.html.
To stop the directory listing, in the service-name folder, I have included a .htaccess file and an index.html file.
Within the .htaccess file I have put Options -Indexes to disable the directory listing, and then put in RewriteRule ^index.html http://www.example.com/service-name.html [R=301,L]
So in short I am trying to redirect the search for the directory to a root level html page. It is not working though. I get a blank page with the service-name directory, which I guess works adequatley because my desire to stop people accessing a directory has come to fruition, but it does not redirect straight to the desired page, which I thought it would have if I included the index.html page in the directory and redirected that?
But when you search for service-name/index.html that redirects properly, so I have clearly missed something! A sharp prod in the right direction would be of use!
Thanks
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'm not amazing with web stuff but I have a small portfolio site which I am redesigning. I am looking to hide the example.com/page.html and make it website.com/page.
I added the rewrite engine which I found on here for the .htaccess
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.html
The only problem is that when I use the RewriteEngine, the original path of /page.html loads as normal, but when i test it as /page/ it seems to lose the style sheet, I've tried relinking the style sheet as .../style.css instead of just style.css, but still all the images and style sheet seem to go missing.
It's probably something pretty damn simple but I need some help here.
what i understood from your words is that you want to make your url like :
http://www.example.com/page
ok . if you don't have to use htaccess , you can do this to do what you want .
just change the file name (page.html) to (index.html) . now create a new folder in your root and move the index.html to there !
and if the file , (page.html) is your home page , just change its name into index.html and leave it alone :D !
Your problem doesn't necessarily have to do with the RewriteRules, but with paths. You should, in general, always use absolute paths to images and assets. So instead of loading style.css or ../style.css, load /style.css or /static/styles/style.css. Otherwise the browser tries to resolve relative to the page location, and /page is considered to be in the root folder while /page/ is thought to be its own folder.
Iow, if you load style.css from your page:
From /page it will load /style.css
From /page/ it will load /page/style.css
Always use absolute paths, save yourself the pain and frustration.
Apart from that, ensure the images and assets are also not rewritten into .html extensions as mentioned in the other answers.
You probable don't want to rewrite every possible extension, so you might want to try something like this:
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
What this should do is check to see if a file exists with an .html extension. If it does it should transparently append .html to the path prior to doing the actual "lookup". So, if you make an HTTP request for
http://yourdomain.tld/somepage
and your site has an HTML page called somepage.html, the actual URL that gets processed will actually be
http://yourdomain.tld/somepage.html
EDIT:
I'm including a Dropbox link for a self-contained example that shows the suggestion above works: https://www.dropbox.com/s/6md9gviv0r2rf9v/xampp.7z
It contains a portable version of Xampp + the source files from this rather nice tutorial: http://coding.smashingmagazine.com/2009/08/04/designing-a-html-5-layout-from-scratch/
Unpack the xampp.7z file somewhere (I recommend the Desktop) and then find and execute the setup_xampp.bat file. It will adjust all the internal paths to your local filesystem. Then, run xampp-control and start Apache. Once that's running, navigate to http://localhost:8080/testsite/ - this is the test site. You should be able to bounce back and forth from http://localhost:8080/testsite/ to http://localhost:8080/testsite/contact - both pages have a .html extension.
HTH.
So I have a URL that I want people to end up on www.website.com/folder/file
The problem is that the URL written on these flyers is something different, www.website/file.
I created a file for www.website/file with a working redirect but people must type in www.website/file.html for the redirect to work. I'd like them to able to type JUST www.website/file without the .html
Anyway this can work? As of now the redirect is using html and working fine. My other possibility is editing my .htaccess file. I am working for a company with coldfusion and I don't see a .htaccess file (hidden files visible) so I'm weary to throw one in there as I fear it might screw something up.
You could rename the file.html as index.html and that should suffice.
E-g; www.domain.com/folder/folder/file.html is same as www.domain.com/folder/folder/
if file.html is called as index.html
There are few different options to solve this, but one of them could be just making a separate folder named "file" and adding there a index.html file.
If possible, I would go for the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/file$ /folder/file [R]
</IfModule>
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule