I have one problem I need advice on.
I want to mask folder names in my website running joomla 3.8 using htaccess rules for example if I open console in google chrome and visit tab Sources I will see structure of my website with following folder:
templates/temlate_name/
I have managed to mask folder name partially using following rules:
RewriteCond %{THE_REQUEST} ^GET\ /real_folder_name/
RewriteRule ^real_folder_name/(.*)$ fake_folder_name/$1 [R,L]
RewriteRule ^fake_folder_name/(.*)$ real_folder_name/$1
and that really changed folder names without breaking site when I go to developer console sources section via chrome
But if I open source code of page I still see real urls example
<link href="/cache/com_templates/templates/ra_template/5791a87f26badb650e42f3790edac52d.css" rel="stylesheet" type="text/css" />
<link href="/media/mod_languages/css/template.css?236ca17ae906371918cc54bf64db39c8" />
Also this method doesn't work if I want to hide for example second folder hidden_folder/still_visible_folder
What am I doing wrong how to manifest changes to source code also ?
Thank you in advance!
But if I open source code of page I still see real urls example
Source could will be as it is .
What am I doing wrong how to manifest changes to source code also ?
Actually , a server receiving a request then first checks whether the request is matching an existing file.
If so, the web server sends the file content back to the browser, If not,server will return an error message to the browser .
Between these two steps you could make specific configuration like handling error requests by sending all of them to custom file and that custom file content , in this case, will be a content that suould back to the browser.
So , when you change the existing file with fake file but redirect a fake file internally to original path , that will happened before sending back a response to browser and nothing will happen in source code then the content of original file will back to browser.
Related
Example.
I have a file site.com/file.html
As expected, I can see file under link site.com/file.html
But unexpectedly I see it under link site.com/file as well. So no extension URI shows, if exists, file with .html extension as far as I can see.
How can I omit this ?
To be closer to real life my PHP application URL site.com/file is overridden by the HTML file placed in the root. Apache doesn't reach my PHP URL, but shows the HTML page. If I remove the HTML file, then PHP-driven url fires. But I must have that .html file there present.
For now I have ended up with Options -MultiViews in .htaccess
So it seems I have enabled MultiViews by default and it works that way I don't need:
The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.
https://httpd.apache.org/docs/current/content-negotiation.html
But I don't see or understand any side-effects for now.
If someone has a better answer, please post.
I'm trying to do a one-off damage-limitation redirection to an anchor on a page on a website. A wrong URL got published in some publicity material, like this:
https://mydomain.org.uk/A/B
when what I really wanted to publish was
https://mydomain.org.uk/A#B
Having looked at some other answers it seems that any redirect with an anchor needs to be an absolute URL. So I put this in my .htaccess:
RewriteRule A/B https://mydomain.org.uk/A.php#B [NE,L]
(note, the .php is correct, A.php is the page file). And it just simply doesn't work. The browser simply loads A.php and displays it from the top.
I know that the rule pattern is matching, because if I make the target be a completely nonexistent page I get a 404 as expected.
Unfortunately my web hosting service doesn't let me use the Apache log, so it's hard to trace what's going wrong. Can anyone guide me to how to do the rewrite properly so that I pass the #anchor all the way through to the user's browser?
Thanks in advance!
When the RewriteRule is processed by the server, it basically changes internally which resource to access, without the browser noticing.
The only way to change the URL in the browser is to use the redirect flag. This will make the webserver send a HTTP 302 response with a Location header, which then will result in the browser changing the URL and requesting the new page. This new URL can contain an anchor.
In your case the following rule should work:
RewriteRule A/B https://mydomain.org.uk/A.php#B [NE,R,L]
Please keep in mind that anchors are a browser feature so they are normally not sent to the server and therefore neither appear in access logs nor can be used in a RewriteRule.
My question pertains specifically to the two pages below, but is also more generally relating to methods for using clean URLs without an .htaccess file.
http://www.decitectural.com/
and
http://www.decitectural.com/about/
The pages above are hosted on Amazon's S3, which does not allow for the use of htaccess files. As a result, I have found no easy way to create a clean url rewrite scheme that sends all requests to an index file which, in turn, interprets the URL using javascript and loads up the correct page (with AJAX, or, as is the case with decitectural, with simple div visibility toggling).
In order to circumvent this problem, I usually edit the amazon S3 bucket properties and set both the index page and the error page to the index.html file. In this case, the index.html file is served even when an invalid path (such as /about/) is requested. This has, for the most part, been a functioning solution... That is, until I realized that I was also getting a 404 with the index.html page which would stop Google from indexing it.
This has led me to seek out an alternative solution to this problem. Currently, as a temporary fix, I am actually creating the /about/ directory on the server with a duplicate of the index.html file in it. This works, but obviously is not a real solution to the problem.
I would appreciate any advice on how to set up a clean URL routing scheme on S3 or in any instance where an .htaccess file can't be used.
Here's a few solutions: Pretty URLs without mod_rewrite, without .htaccess
Also, I guess you can run a script to create the files dynamically from an array or database so it generates all your URLs:
/index.html
/about/index.html
/contact/index.html
...
And hook the script on every edit, in a cron or run manually. Not the best in terms of performance but hey, it should work.
I think you are going about it the wrong way. S3 gives you complete control of the page structure of your site. If you want your link to be "/about", just upload a file called "about", and you're done. (Set the headers so that the browser knows it's HTML.)
Yes, it will break if someone links to "/about/" or "/about.html". But pretty much any site will break if you mess with their links in odd ways. You will have to be vigilant when linking to your own site, because you won't have any rewrite rules to clean up for you. But you should have automation doing that.
I´ve just made a website based upon an only index.html file. You can surf the file using the menu that is made of anchored lists. The problem is that the URL is the name of the anchor, so I have two options:
1.- Rename the whole anchored lists (but there would be still some problems)
2.- Rename the URL using .htaccess, doing RewriteEngine On.
The URL you can see when access to the homepage is:
http://domain.com/#!/page_home
Notice: Only 'domain.com' is not real.
And next 'pages' are then:
http://domain.com/#!/page_2
http://domain.com/#!/page_3
http://domain.com/#!/page_4 and so on...
And I want to be displayed http://domain.com/welcome instead http://domain.com/#!/page_home.
Well, I´ve follow some basic and advanced tutorials with no luck. In theory using something like this should work:
RewriteEngine On
RewriteRule ^#!/page_home welcome
But this and others combinations didn´t work for me.
.htaccess is working because I have another rules like this one:
Options -Indexes
ErrorDocument 404 /notfound.html
Can you give me a hint please?
Thanks in advance.
I'm sorry to tell you this, but it won't work.
As you know already, anchor is a link to an internal resource in a web page. When you click on an anchor, no request is sent to the server, only the browser goes to the requested resource in the same page. If no request is sent to the server, then no htaccess is called and no redirections are made.
Your only option if you want the links to be like that is to redo the website without using anchors ...
I've been asked to figure out how the Concrete5 system works for an employer, and I can't figure something out.
I have Concrete5 installed to a directory on the server called /realprofessionals. When the Concrete5 system makes new pages, it gives them their own absolute paths, for instance:
http://www.wmcpartners.com/realprofessionals/footer
However, it hasn't actually made a folder in the /realprofessionals directory called footer. So how does that work? How can http://www.wmcpartners.com/realprofessionals/footer be a working link?
Short answer: All page requests are actually going through the one and only index.php file. Page content is stored in the database, not in files on the server.
Long answer:
Concrete5 (and most PHP-based CMS's for that matter) work like this: all requests are routed through the index.php file. This routing is enforced with some mod_rewrite rules in the .htaccess file. The rules say "for any request, don't actually go to that page, but instead go to index.php and pass the rest of the requested path as $_GET parameters". Then in the index.php code (or some other code that is included by the index.php file), the requested page is determined based on the path that was put into the $_GET parameters by Apache (as per the mod_rewrite rule in .htaccess), and the appropriate content is retrieved from the database.
Storing content in the database as opposed to files on the server has several advantages. For example, you can re-use the same html template -- header, footer, sidebar -- on every page, and if you change the template it will automatically be reflected on all pages it's used on. Also, it makes it easier to shuffle pages around and to give them whatever URL you want (e.g. no ".php" extension at the end, or /2010/11/date/based/paths/for/blog/posts).
The disadvantage of course is that every request requires many database queries, but for most sites (those without zillions of page views), the trade-off is well worth it (and various types of caching can help reduce the performance hit).
Jordan's answer is excellent, I would add that you probably don't see index.php in the url because you've enabled pretty URLs (type 'pretty' on concrete5's searchbox to check that).
Anyhow, the best way to programmatically add link to internal pages is:
<a href="<?=$this->url('page-name');?>">
page name
</a>
It works both on localhost and online, with or without pretty URLs.
(For the page-name go to dashboard/full sitemap/page-name/properties/page paths and location.)