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.
Related
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.
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.
What I'm trying to do is have a single dynamic file that takes a parameter to affect content (/view.html?k=about) but uses history.pushState to change the URL to something more user-friendly (ki/about). In addition, anytime an AJAX call is made on content.html to load new content, it updates the URL according, (e.g. if products are loaded via AJAX, change URL to keywords/products).
My current solution is any path requested from ki is redirected via .htaccess to the view.html page. view.html then uses history.pushState to change the URL. As links are clicked, the URL updates. The problem with this, however, is it causes a infinite loop.
Here is my .htaccess file, residing in the /ki/ folder.
RewriteEngine on
RewriteRule ^(.*)$ /concept/view.html?k=$1 [R=permanent,L]
What can I do to get my desired result? If there's a way to achieve the same thing without the .htaccess file then that's acceptable too.
You are going to want to rewrite any url that goes in the form of ki/about to the /view.html?k=about behind the scenes.
history.pushState is only really meant to be used for web applictions like Spotify that don't reload the page but would still make sense to have the back button have some functionality.
That way, urls can be shared without giving 404 pages.
I have not tested this but I am sure you want something like this
RewriteRule ^ki/([A-Za-z]+)/$ /view.html?ki=$1
If the user types in the ugly url, they will still get to the same page no problem. But the pretty urls will direct users to the right webpage.
For more info you can go here.
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
so i developed a simple website which is using ajax call to html files to display.
the issue is that the search engine like google find the html file, and when we click on the link we see a poor html file out of context of the website of course.
so im guessing i have some work to do with htaccess file to handle this but how ?
my idea is to use htaccess rewriterule to redirect any .html file to the main index.php file.
something like that :
- www.my.com/team.html will call www.my.com/index.php which will detect the query-string team.html and will proceed to ajax loading the corresponding html file.
how is that possible please ?
Generally all search engines respect the terms set in the robots.txt file. If you wish that files in a particular folder in your site should not be crawled, the robots.txt can instruct the search engine to obey.
If you wish to lern about it, here is the link: http://www.robotstxt.org/robotstxt.html
You may see http://www.google.co.in/robots.txt for example.
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.