.htaccess how to make my URL shorter? - .htaccess

My current URL:
http://localhost/vavis/public_html/index.html#/users
I wan't to be like this:
http://localhost/users

Looks like you'll need to rely on javascript or something on the client side to handle this. The "/users" part of the url is part of a fragment (after the "#") which isn't even sent to the server, so there's no way anything in the htaccess would know you were trying to access /users.
There's some more information about URL fragments here: https://www.oho.com/blog/explained-60-seconds-hash-symbols-urls-and-seo
So depending on how it got there and why you need it, it may not be as simple as simply removing it or encoding it into something else.

Related

Remove question mark from URL query

Is there any way I can remove the question mark from URL using Mod_Rewrite like this?:
domain.com/controller-name?parameter/parameter/parameter
to change question mark after controller-name to slash
domain.com/controller-name/parameter/parameter/parameter
I want to add this to htaccess in PrestaShop, where I send query like this: parameter/parameter/parameter to controller.
Normal Presta URL is domain.com/index.php?controller=controller-name and I set on SEO settings friendly URL to this controller to rewrite to only controller-name so SEO friendly URL is domain.com/controller-name .
To send some parameters to this controller I can use URL like this: domain.com/controller-name?(here parameters)
In my controller I grab parameters after question mark ? and show content according to this parameters. The parameters are separated by a slash. So I want to get rid of question mark and replace it by slash to get: domain.com/controller-name/(here parameters) with parameters I want to look like this domain.com/controller-name/parameter/parameter/
When I use URL domain.com/controller-name/parameter/parameter/ shows error 404 and Presta don't see that I want content from controller-name.
I think it is achievable by mod_rewrite rule in .htaccess, but I don't know how to write rule according to this problem.
OR maybe there is a way to add something to controller or SEO configuration in Presta to work with / instead ? in query... that would be great solution...
You can use the history.pushState and history.popState to change the URL in the browser which won't cause a page reload. But the problem is that old browsers don't support this.
Alternatively, you can set the window.location.hash property to a value that contains whatever state information you need, then either use the window.onhashchange event, or for older browsers that don't support onhashchange (IE < 8, Firefox < 3.6), periodically check to see if the hash has changed (using setInterval for example) and update the page. You will also need to check the hash value on page load to set up the initial content.
If you're using jQuery there's a hashchange plugin that will use whichever method the browser supports. I'm sure there are plugins for other libraries as well.
One thing to be careful of is colliding with ids on the page, because the browser will scroll to any element with a matching id.

Preventing shortened URL (by htaccess) resolving

This is for bit of a knowledge gainer for me really, everyday is school day and I like to know what is possible, and not try to have a go at something is impossible.
I have with help here (.htaccess to hide 2 folder paths) shortened the full path so people access the website don't know the full directory.
My problem is now that I would like the short URL if typed in not too resolve, but only can be navigated through, I want the URL just be purely for display I suppose, and if it was to be entered it wouldn't work. Is this possible?
You can't do this with .htaccess rewrite rules — if the URL works in a link, then it also works if typed in.
(OK, technically you could make your rewrite rules conditional on the presence of an appropriate HTTP Referer (sic) header, but that's not something you really should rely on.)
What you could do is fake the URL shown in the browser's address bar using the JavaScript History API, like this:
history.replaceState({}, "", "/whatever")
(Try running that in your browser's JS console!)
Of course, that's a purely cosmetic change; you'd still need to use the real URL of the page in your links, and it would be trivial for anyone with a basic understanding of how web browsers work to figure out the real URL. It also has the annoying side effect that reloading the page will cause the browser to try to load the fake URL, likely breaking the page. But that's pretty much inevitable; there's effectively no difference between reloading a page and typing its URL into the address bar. But if you're OK with all that, it could be one way to go.
Honestly, though, I suspect that what you really should do is to stop trying to do this, and instead take a step back and try to find an alternative solution to your real problem, whatever it may be.

Notes 9, rewriting URLs

How do you rewrite a URL in Notes 9 XPages.
Let's say I have:
www.example.com/myapp.nsf/page-name
How do I get rid of that .nsf part:
www.example.com/page-name
I don't want to do lots of manual re-direct because my pages are dynamically formed like wordpress.
I've read this: http://www.ibm.com/developerworks/lotus/library/ls-Web_site_rules/
It does not address the issue.
If you use substitution rules like the following, you can get rid of the db.nsf part and call your XPages directly as example.com/xpage1.xsp:
Rule (substitution): /db.nsf/* -> /db.nsf/*
Rule (substitution): /* -> /db.nsf/*
However, you have to "manually" generate your URLs without the db.nsf part in e.g. menus because the XPages runtime will include the db.nsf part in the URLs if you use for instance the openPage simple action.
To completely control what is going in and out put your Domino behind an Apache HTTP and use mod_rewrite. On Domino 9.0 Windows you can use mod_domino
You can do it with a mix of subsitutions, "URL-pattern" and paritial refresh.
I had the same problem, my customers wants clean URLs for SEO.
My URLs now looks like these:
www.myserver.de/products/financesoftware/anyproduct
First i used one subsitution to cover the folder, database and xpage part of the URL.
My substitution: "/products" -> "/web/techdemo.nsf/product.xsp"
Problem with these is, any update on this site (with in redirect mode) and the user gets back the "dirty" URL.
I solved this with the use of paritial refreshes only.
Last but not least, i uses my own slash pattern at the end of the xpage call (.xsp)
In my case thats the "/financesoftware/anyproduct/" part.
I used facesContext.getExternalContext().getRequestPathInfo() to resolve that URL part.
Currently i used good old RegExp to get the slash separated parameters back out of the url, but i am investigating a REST solution at the moment.
I haven't actually done this, but just saw the option yesterday while looking for something else. In your Xpage, go to All Properties, and look at 'navigationRules' and 'pageBaseUrl'. I think you will find what you are looking for there.

htaccess remove part of the url

I have urls structured like this:
/!#/pretty-url/
I need to remove the !# so the urls will look like this:
/pretty-url/
What would be the correct .htaccess rule to do this?
When you have a # in the URL then that is a named anchor. The browser does not send anything to the right of a # to the server. This means that all the rewrite engine is seeing is:-
/!
If you want your URLs to look like this then you are going to need to use JavaScript to get the relevant content via AJAX.

htaccess redirect conditions

I figured out how to redirect someone, if they happen across one particular filename:
Redirect /index.php http://www.website.com/#myaccount
As you can see, I'm pretty much redirecting that visitor to the same page, which doesn't work. It's an endless look, regardless of the slight/minuscule change.
I want to force someone to see a part of the page, by adding the hash. (it's a little weird, I know)
I'm guessing this may be a time to use regex in the htaccess file.
But I thought I'd ask if there's a simpler way to do this from the htaccess file.
The fragment of an URI (the part after the first #) is not sent to the server. That means you cannot use server side techniques to test if the fragment has a certain value of does exist at all; only client side techniques like JavaScript can do that.

Resources