I need a help in .htaccess modification.
I have an index.html , contact_us.html, about.html, faq.html (pages)
But I'd need a simple .htaccess rule to Override those .html extension.
Like this, instead of yoursite.com/contact_us.html a user can still access your contact webpage using yoursite.com/contact_us
Even with or
without the .html extension.
They can still get to the same page they meant to access.
Multiviews. Add this to your .htaccess:
Options +Multiviews
This will also let you keep the same URLs if you later decide you'd rather be working with index.pl or index.php.
Related
My Wordpress website, www.the-family-historian.net, goes directly to /index.html, which doesn't exist. I have it set in the Wordpress backend so that the landing page is the posts (blog) and not a static page, but this "index.html" seems to be blocking it. Thanks for any help!
Try setting the following at the top of the .htaccess file:
DirectoryIndex index.php
This should force any request to go to index.php first and ignore index.html, not a 301 redirect though.
Using an FTP program, or possibly a web based file manager, view the files that make up your website. Find an option to view "system / hidden files" in order to view the .htaccess file. I suspect you will find a rewrite rule in it pointing to index.html Simply change that to index.php and all should be good.
I tried this
Options +Indexes
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
HeaderName /header.html
ReadmeName /footer.html
IndexIgnore header.html footer.html .htaccess
How To Include a PHP File Site-wide Using .HTACCESS or other methods
Apply .htaccess HeaderName to all lower levels?
How To Include a PHP File Site-wide Using .HTACCESS or other methods
It just simply does not do anything. I also followed an old guide to enable Layout Header (something with mod_layout in apache) but it seems it's too old.
The best i managed to do is to show the content of my "header.html" into the directory (which is listed with Option +Indexes)
I am doing all of this in a specific folder .htaccess, not in the root .htaccess
It looks like this :
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble
HeaderName header.html
Please, help
I think you're confusing HTTP Headers with a HTML "Header" (meaning the top of the page)
A HTTP header is used to define things like the encoding, content type (eg JSON/XML), not to add HTML to the top of another HTML page.
If you want to add HTML to the top of each page, .htaccess isn't the place to do this - you need to use some kind of scripting/programming language (eg ASP/PHP) to include the files.
Note that none of the three SO questions you link do what you want either:
How To Include a PHP File Site-wide Using .HTACCESS or other methods and How To Include a PHP File Site-wide Using .HTACCESS or other methods both use PHP to include the files (and just use htaccess to tell PHP where to find the files).
Apply .htaccess HeaderName to all lower levels? as you discovered, adds the header to the Apache directory listing page only, not to every page on your site.
If someone has the same problem, when you write the full path, /www/pages/header.html is not enough, you must write /home/User/www/pages/header.html (if you're on linux or C://etc... on windows)
Why? because it is shown on several folders (recursively), so the path changes depending on the directory you're in
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
I want to create a single page such as this:
http://www.mywebsite.com/special/index.html
But anything in the /special/ folder should be able to load the index.html page. For example, if you go to
http://www.mywebsite.com/special/another-page.html
It should still load the index page but not change the URL in the browser or to search engines. Basically, you should be able to go to any page in the /special/ folder, keep the URL the same as you enter, but always load the index.html page. Any ideas?
A 404 or 301 redirect wouldn't work because that changes the URL in the browser and to search engines...
Thanks in advance!
A 404 redirect would not help, but a custom 404 handler would:
error404.php:
<?php
include('path/to/special/index.html');
?>
Assuming .html is a static or PHP page. If it is something else, youse the equivalent construct of that environment.
Using apache mapping it should be possible. I don't how to exactly do that but this doc http://httpd.apache.org/docs/2.0/urlmapping.html probably has the answer.
It is possible to use patterns to map URL to filesystem locations.
I think (untested) something like this would work in an .htaccess file in the special directory if you have the ability to use rewrite rules:
RewriteRule ^.*$ index.html
You would have to symlink index.html in the special directory to the real index.html.
The ^.*$ just means (beginning of line)(any amount of anything)(end of line) - basically a wildcard; there might be a better way of writing it.