Why is a URL not returned when using the pathto(document) helper function? - python-sphinx

According to the Sphinx docs on templating, pathto(document) returns the path to a Sphinx document as a URL." By definition, a URL typically includes the scheme, the host, and the path component. So, why does pathto(root_doc) return index.html instead of, for example, https://example.com/index.html? index.html is not a URL. Can someone enlighten me? What is the best way to get an absolute URL for a document in Sphinx?

Use the setting html_baseurl. Without setting that value, the default is '', which omits the protocol and host.

Related

mod_rewrite anchors applied to the same document

I have a onepage-design and the anchors are defined to the ID's of some section-containers.
Is it possible to change the anchors who are applied to the same document?
For example, i need something like that:
change: directory/index.php#premium-office
to: directory/premium-office.html
If anything is unclear, please let me know.
You can't do anything like that server side, because the fragment part of the URL (the thing after the # symbol) isn't sent to the server.
Because of that you can only use JavaScript to make the redirect.

Codeigniter URL routing solution for my website

I have a website that is developed with CodeIgniter. I have added the route for my url as follows:
$route['about_us'] = 'about-us';
Now I have a problem with that. I.e. when I am looking for the url www.mysite.com/about_us it works and at same time www.mysite.com/about-us is also working. I want only one url to work: the one with the underscore.
I have removed this to:
$route['about_us'] = 'about-us';
But the url www.mysite.com/about-us still works. It may cause duplicate content for my website in Google and so more page links also showing. Even I don't have that functions too. Like www.mysite.com/about_us/design. Likewise in about_us controller file index function only there, but design method calling in Google.
How do I resolve this problem?
You actually don't need a route here. The normal purpose of request routing the way you are using it is so that you can use hyphenated URLs when hyphens are not permitted in class and function names. I.E. you want the url to by www.example.com/test-controller, but you can't actually name a controller test-controller because the hyphen is illegal.
If you only want to have the underscored URL such as www.mysite.com/about_us then just remove the route completely and name the controller about_us. With no routing rules the hyphenated url should 404.

How to differentiate from the server side, between the first request of the browser (HTML file) and the following (images, CSS, scripts...)?

I'm programming a website with SEO friendly links, ie, put the page title or other descriptive text in the link, separated by slashes. For example: h*tp://www.domain.com/section/page-title-bla-bla-bla/.
I redirect the request to the main script with mod_rewrite, but links in script, img and link tags are not resolved correctly. For example: assuming you are visiting the above link, the tag request the file at the URL h*tp://www.domain.com/section/page-title-bla-bla-bla/js/file.js, but the file is actually http://www.domain.com/js/file.js
I do not want to use a variable or constant in all HTML file URLs.
I'm trying to redirect client requests to a directory or to another of the server. It is possible to distinguish the first request for a page, which comes after? It is possible to do with mod_rewrite for Apache, or PHP?
I hope I explained well:)
Thanks in advance.
Using rewrite rules to fix the problem of relative paths is unwise and has numberous downsides.
Firstly, it makes things more difficult to maintain because there are hundreds of different links in your system.
Secondly and more seriously, you destroy cacheability. A resource requested from here:
http://www.domain.com/section/page-title-bla-bla-bla/js/file.js
will be regarded as a different resource from
http://www.domain.com/section/some-other-page-title/js/file.js
and loaded two times, causing the number of requests to grow dozenfold.
What to do?
Fix the root cause of the problem instead: Use absolute paths
<script src="/js/file.js">
or a constant, or if all else fails the <base> tag.
This is an issue of resolving relative URIs. Judging by your description, it seems that you reference the other resources using relative URI paths: In /section/page-title-bla-bla-bla a URI reference like js/file.js or ./js/file.js would be resolved to /section/page-title-bla-bla-bla/js/file.js.
To always reference /js/file.js independet from the actual base URI path, use the absolute path /js/file.js. Another solution would be to set the base URI explicitly to / using the BASE element (but note that this will affect all relative URIs).

how does URL rewrite work in plain english

I have read a lot about URL rewriting but I still don't get it.
I understand that a URL like
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19
can be replaced with a friendlier one like
http://www.example.com/Blog/2006/12/19/
and the server code can remain unchanged because there is some filter which transforms the new URL and sends it to the old, but does it replace the URLs in the HTML of the response too?
If the server code remains unchanged then it is possible that in my returned HTML code I have links like:
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=20
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=21
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=22
This defeats the purpose of having the nice URLs if in my page I still have the old ones.
Does URL rewriting (with a filter or something) also replace this content in the HTML?
Put another way... do the rewrite rules apply for the incoming request as well as the HTML content of the response?
Thank you!
The URL rewriter simply takes the incoming URL and if it matches a certain pattern it converts it to a URL that the server understands (assuming your rewrite rules are correct).
It does mean that a specific resource can be accessed multiple ways, but this does not "defeat the point", as the point is to have nice looking URLs, which you still do.
They do not rewrite the outgoing content, only the incoming URL.

Serving images for a cakePHP site from a different sub-domain

what is the best practice for serving images from a different sub-domain(like media.host.com) in cakePHP? Should I put the images in the img folder provided by cakephp and make this folder the document root of the sub-domain, or is there a better way of doing this?
Roland.
I don't think it matters as long as the images are in the same place. In any case you can't use $html->image() as is, or you can but it's probably wiser to modify it or roll your own helper so that you don't have to always give it the full path. While you're doing that you can just make it use whatever url root you want.
all you need to do is set IMAGES_URL constant before cake does, or even overload image() in AppHelper. if you are some how using array urls for images you would also need to overload url() in AppHelper
I personally just created a separate subdomain pointing to the Cake webroot, which would only serve static files (so deny Cake's index.php, for example). A custom webroot() method in AppHelper modifies the URL for every returned webroot path (script(), image() and css() all use this) so no further code changes are needed.
I wrote a short article about it here: http://metaphoric.nl/blog/serving-static-content-from-a-separate-subdomain-in-cakephp

Resources