WebURK without any kind of subdirectories - web

It is my first time seeing something like this.
Does anyone know, what the name/kind/type of the website is that does not have any kind of subdirectories on the web-URL page, and it always just stays as a plain domain name, and how it was made, and how it can be avoided since I need to send an API call to one of those subdirectories?
Example:
I have a website let's call it example.net. It has UI page and it has a home page, which should look like this in a browser: example.net/home, or it has a /shipment option inside of the UI page. So the URL should look like this:
example.net/shipment and it has one more subdirectory inside for example /report, and if I select it, it should look like this: example.net/shipment/report (something like this).
And open up that subdirectory, but again web-URL link on a website continues to stay just as a example.net all the time.
And for some reason whatever subdirectory I would go on a website, Web-browser URL will remain as a hello-world.net all the time without any kind of changes subdirectories on a web-browser URL.
It is an internal website, so I can not post examples of it from work here.
Does anyone knows, what the name of that kind of set?
How it can be avoided? Since I need to send an API request to one of the subdirectories?
I am not a developer, and I am new to IT, so I am not really sure, what the name of this, and how does it works.

If you are on example.net/shipment and you want to link to a subdirectory, the link needs to include that subdirectory. You have two possibilities:
Root relative links: <a href=/shipment/report>
Absolute links: <a href=https://example.com/shipment/report>
If you shipment directory has a trailing slash (example.net/shipment/), you a third possibility. (Note this only works with a shipment URL that is different than what you specified in your question.)
Document relative links: <href=report>
There is no name for websites that don't have subdirectories that I know of. Websites are often set up like this to make the URLs easy to type and remember which helps with SEO.

Related

.htaccess: redirect specific link to another?

I have these three links:
localhost/my_projects/my_website.php
localhost/my_projects/my_website.html
localhost/my_projects/my_website
The paths of the php and html files are as follows:
C:\xampp\htdocs\my_projects\my_website.php
C:\xampp\htdocs\my_projects\my_website.html
The link without an extension is "artificial" and I want to use said link:
localhost/my_projects/my_website
to get the contents of either of these links:
localhost/my_projects/my_website.php
localhost/my_projects/my_website.html
The reason for the two example files, instead of just one, is that I want to be able to switch between those two files when I edit the htaccess file. Obviously I only want to access one of those files at a time.
What do I need to have in my .htaccess file inside the my_projects folder to accomplish that? How can I make one specific link redirect to another specific link?
After reading your comment clarifying your folder structure I corrected the RewriteRule. (By the way, it would be best if you add that info to the question itself instead of in comments).
The url you want to target is: http://localhost/my_projects/my_website
http:// is the protocol
localhost is your domain (it could also be 127.0.0.1 or a domian name like www.example.com in the Internet)
I assume you are running Apache on port 80, otherwise in the url you need to also specify the port. For port 8086 for example it would be http://localhost:8086/my_projects/my_website.
The real path is htdocs/my_projects/my_website.php or htdocs/my_projects/my_website.html depending on your needs (obviously both won't work at the same time).
Here the my_projects in the "fake" url collides with the real folder "my_projects" so Apache will go for the folder and see there is no my_website (with no extension) document there (it won't reach the rewrite rules).
There is a question in SO that provides a work around for this, but it is not a perfect solution, it has edge cases where the url will still fail or make other urls fail. I had posted it yesterday, but I seem not to find it now.
The simple solution if you have the flexibility for doing it is to change the "fake" url for it not to collide with the real path.
One option is for example to replace the underscores with hyphens.
Then you would access the page as http://localhost/my-projects/my-website if you want to keep a sort of "fake" folder structure in the url. Otherwise you could simply use http://localhost/my-website.
Here are both alternatives:
# This is for the directory not to be shown. You can remove it if you don't mind that happening.
Options -Indexes
RewriteEngine On
#Rule for http://localhost/my-projects/my-website
RewriteRule ^my-projects/my-website(.+)?$ my_projects/my_website.php$1 [NC,L]
#Rule for http://localhost/my-website
RewriteRule ^my-website(.+)?$ my_projects/my_website.php$1 [NC,L]
(Don't use both, just choose one of these two, or use them to adapt it to your needs)
The first part the rewrite rule is the regular expression for your "fake" url, the second part is the relative path of your real folder structure upto the page you want to show.
In the regular expression we capture whatever what we assume to be possible query parameters after .../my_website, and paste it after my_website.php in the second part of the rule (the $1).
Later on if you want to point the url to my_website.html, you have to change the second part of the rule, where it says .php, replace it by .html.
By the way, it is perfectly valid and you'll see it in most SEO friendly web sites to write an url as http://www.somesite.com/some-page-locator, and have a rewrite rule that translates that url to a page on the website, which is what I had written in my first answer.

Keep people from opening pdf directly on my webiste

I am not sure if this is possible, but I figure I would ask.
I have hundred of PDF's stored on my website, and they are all getting indexed directly by Google, so people are doing a search and the engine is taking them directly to the PDF. The issue here is that the PDF's are related to language learning and have audios that go with them. If a visitor goes directly to the PDF, then they never see the audios.
I have another page I have designed which opens up the PDF in an Iframe, and shows the audios right next to them so the users can use it.
So my question is, is it possible to redirect a user who opens:
www.mywebsite.com/something.pdf
And have it redirect them to:
www.mywebsite.com/page-with-audios/
The key here is that the pdf should still open in the IFrame on my domain.
Thanks in advance for any assistance.
If you use routing, you could make a route which has the PDF name as parameter. The route could look something like this:
/{PDF_NAME}.pdf
This could be used to match all PDF's, like example.com/foo.pdf, example.com/bar-baz.pdf. Since you then have the name of the PDF they would like to view, you can redirect them to the /page-with-audio-files with some extra data like the name of the PDF. Then you can handle opening the iFrame.
EDIT
since I now see your question was directed at .htaccess, I think the following might work too.
add this rewrite to your .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z\-]+.pdf)$ /page-with-audio/$1 [L, R=301]
This will make the $1 variable somepdf.pdf if your request url is http://example.com/somepdf.pdf.
Then it redirects the user to http://example.com/page-with-audio/somepdf.pdf so you know which pdf was requested.

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.

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.

Using one directory with different aliases using .htaccess

I'm redeveloping a site (replacing it with one based on CodeIgniter), which is currently a horrid mess of repeated procedural code, however, it has good search engine rankings. Because of this, I need to keep the exact same URL structure.
The company has many different quote pages, which are all essentially the same - so I've produced one clean version which can be used everywhere.
The quote system is now in a folder called /get-quote, but due to the old URLs being required, that folder mustn't be visible anywhere.
I'd like the following to happen, but don't know how to:
A user accessing /insurancequote.php should (on the server) load the /get-quote/ directory (which in turn will load the default CI route). The Base URL in CI should be http://www.mysite.com/insurancequote.php (I'm able to do that bit), so moving to step 2 would result in: http://www.mysite.com/insurancequote.php/step2 (which would map to /get-quote/step2).
Secondly, a user accessing /brokerquote.php should show mysite.com/broker in the address bar (redirect?), but on the server access /get-quote/broker.
Thirdly, a user accessing one of many broker-specific pages, e.g. mysite.com/brokername1.php or mysite.com/broker/brokername2.php (yep, they are scattered all over the place! - but I do know where each one is) should show mysite.com/broker/brokername1 or mysite.com/broker/brokername2. On the server, /get-quote/broker/brokername1 or /get-quote/broker/brokername2 should be accessed.
I don't think what I've written is completely clear, so maybe sudocode helps:
If '/insurancequote.php'
Dont Redirect
Use '/get-quote/'
If '/brokerquote.php'
Redirect '/broker/'
Use '/get-quote/broker/'
// Do the following (manually) for each broker
If '/brokername1.php'
Redirect '/broker/brokername1/'
Use '/get-quote/broker/brokername1/'
If '/brokers/bname2.php'
Redirect '/broker/brokername2/'
Use '/get-quote/broker/brokername2/'
If '/mybrokerpage.php'
Redirect '/broker/mybroker/'
Use '/get-quote/broker/mybroker/'
Is this possible? If so, how would I go about doing it?
Thanks!
The risk you take is messing up your new clean code for historical reasons (and the guy coming next you will say, WTF, this is a mess!).
For me the right solution would be handling the url migration in apache and not in your application. Every refferenced url that you do not want to keep should get a 410 - Gone message (think about referenced images for example) and every referenced page which have a new matching page should get a 301 - moved permanently redirection on the right page. Then after some time as gone check the access log of your server, and if nobody checks the old url anymore then remove the rules.
If you know every old url and every matching url then use a matching url file (or hash file, faster) and manage the redirection 301 with rewriteMap. You can have a really big number of files in a hash file, the match should be fast. And it should be a temporary function, waiting for robots to fix the urls.

Resources