Preventing shortened URL (by htaccess) resolving - .htaccess

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.

Related

AGAIN: how to hide subdirectories in browser bar with htaccess

Sorry to bother you perhaps again, but I can't get it working after trying at least 30 answers already given on this subject!!
I use a somewhat deep directory structure and the I would like to rewrite the address browser bar of all subdirectories been replaced by one: simply (www.)example.com/subdirname. Even if I redirect from within the subdirectories to a higher level.
In other words:
So I have: http://www.example.com/subdirname ----> this what I would like to show every time. Here is also my main index.html located.
Then the structure beneath is e.g. www.example.com/subname/text/image/magazine/xxx.html
I have tried all the REWRITE CODES available (well, practically). But nothing works.
Can and will someone please give me the ultimate answer how to code this in htaccess? Please don't forget to tell me please, in which directory I should place this htaccess (allthough I tried all).
By the way, I don't care about SEO - the (sub-)pages don't have to be 'searchable'.
By the way, this is a site which I like to protect a little against theft, since it concerns my living of bookselling.
Thanks a lot beforehand!
Rokus
There is one way to do this, a frame redirect.
That'll always show the same URL in the address bar - but it's trivial to find the actual URL for anyone with the slightest bit of technical knowledge.
Users will also be unable to link to a specific page or magazine.
If you have intellectual property you want to protect, it might be worth looking into other, more suitable ways to do so.

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.

Magento URL adding random string

Currently have a Magento install running which seems to be printing #.UD3vymhSSYV at the end of every product URL. I assumed I could remove it using the htaccess file, however whenever this is done it generates a different random code.
http://domainname.com/gentlemans-tall-coat-wallet#.UD3vymhSSYV
As you can see above. Im just stumped not sure where it is coming from or how to get rid of it.
Any help would be great.
THIS ANSWER IS POSSIBLY WRONG:
Harmless - you has some ADDTHIS extension added.
Their URLs are like: http://www.addthis.com/browser-extensions#.UD4zyRVFcal
No further action needed but you may want to get rid of the 'addthis' stalker code.
THIS ANSWER IS MOSTLY WRONG:
That does not look like a Magento SID string to me.
You may have a compromised server with someone able to write/inject stuff into your index.php./.htaccess
Fire up the site on localhost and make sure that install files are as they should be, particularly index.php and .htaccess.
The server may be compromised with a common attack on whatever else is on the box, e.g. Wordpress, Expression Engine or anything else with known vulnerabilities.
As for what the anchor string does, this may not be obvious to you but could be just for the search engines to pick up - check your site isn't a 'viagra' site on Google.
Don't panic though - it is unlikely that the DB of Magento is compromised.
Yes, it is done by addthis script.
See how to remove :
http://support.addthis.com/customer/portal/articles/1013558-removing-all-hashtags-anchors-weird-codes-from-your-urls#.UrGWX_QW314

CakePHP nice urls - how to prevent normal urls from working

I have a website that's written using CakePHP. I've added some rewrite rules in the .htacces file to change the default urls to different ones (instead of /controller1/action1/parameter I have /some-string-about-controller-and-action/parameter, for example).
The problem is that now both the normal url and the nice one are available, and google seems to be indexing both, which is a problem. I'd like to only keep the nice one, which is the proper way to handle this so that it affects the google results as little as possible?
I don't know why you don't want to use cakes own routing (if you are having trouble doing what you want, you can accomplish what you want with a custom route class), then make sure that you redirect all relevant URL's in your .htaccess file to the desired URL using a MOVED PERMANENTLY redirect.
This way google will index the target url instead of the one that is undesirable. You are right to take offense to this, double indexing is a great way to harm your SEO rankings.

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