Rewritten htaccess URL being cleared by hash - html

I have a page with a RewriteRule like this:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ index.php?user=$1&language=$2 [QSA,L]
In the index.php page, I have several links pointing to hashes # of element ids. When the user lands on the page, he gets this nice looking url:
mydomain.com/username/en
Which points to
mydomain.com/index.php?user=username&language=en
The problem is, as soon as one of the links is clicked, the browser changes the url to
mydomain.com/#id
Isn't it supposed to change to something like this?
mydomain.com/username/en#id
I want my url to look like the one above, that seems to be the expected behavior of the page...
Any thoughts on this?

Nevermind... just found the problem
I was using JS to push history states and it ended up messing with the urls!

Related

How do I accomplish this with url rewriting?

I have a menu, which when you open goes to /#0 to indicate that the menu has been opened and the menu the slides in and shows. What I want to know is how to rewrite the url so that instead of site.com/#0 we simply get site.com. I believe this can be done with .htaccess though I'm not quite sure how. Thanks in advance.
Please try this if I'm getting your point.
# Rewrite --- www.site.com/#0 => www.site.com
RewriteRule ^$ /?&%{QUERY_STRING}

Routing in static html landing page

I have a small portfolio landing page based on js/css/html. No frameworks/CMS, just pure static html. Entry point is index.html file with content on English language.
I want to use translations on my site: index.ru.html, index.ua.html, but I don't want to see any *.html or index.ua in the address bar. User can change a language by buttons on top of my page.
How can I route:
http://mysite/en to display index.html - first enter to site
http://mysite/ru to display index.ru.html
http://mysite/ua to display index.ua.html
?
Also can I route to specific div/section html tag: user enter http://mysite/ru/contacts to display contacts section in index.ru.html? Scrolling page also must change url... is it real or not?
Maybe I need to use micro-framework for my small needs?
EDIT:
Found good example on this site - http://www.even.lv/
Try adding this to your Root/.htaccess :
RewriteEngine On
RewriteBase /
RewriteRule ^en/?$ index.html [NC,L]
RewriteRule ^(ru|ua)$ index.$1.html [NC,L]
This will redirect "/en" to "/index.html" and "/ru" to "index.ru.html".
Might be using bootstrap scroll spy you can take user to sepecific section. if you don't want url to be change in that case ajax will help you. with use of jQuery you can trigger select change function jQuery("#language-select").change(function(){ // your logic try ajax here to change portion on page. })
Make directories for each language and put the relevant pages inside.
The only mechanism you have that allows you to omit a full url is the ability of the web server to serve a "default" page, which in your case is an index.html
By the same token to support mysite/ru/contacts you would need a directory structure of:
mysite/
ru/
contacts/
index.html
In other words, with pure html pages and without using rewrites, you can accomplish your structure with directories off the webroot and creating many individual index.html pages.
The other option is to use rewrite rules like those available using mod_rewrite and the apache web server.
Those rules require a good working understanding of regular expressions.

Use history.pushState while ignoring/bypassing .htaccess (alternative solution welcome)

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

htaccess- only one page redirects from html to php

This is normal question, but i am very weak regarding .htaccess
I have one website in html.All Pages are in .html. Now only enquiry page is enquiry.php
So I want enquiry page from enquiry.php to enquiry.html in URL.
It should not affect other html files
Pls help
Provided you've already turned "RewriteEngine On" your rule might looks something like this:
RewriteRule ^enquiry.html$ /enquiry.php [QSA,L]
However depending upon your web host, that may not work out of the gate. For example, you might need to add a slash before the .html so it would read:
RewriteRule ^enquiry\.html$ /enquiry.php [QSA,L]
I've also seen where you may need to add "Options FollowSymLinks" to the top of the .htaccess file.

Load same page with different URLs?

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.