Forum Moderators: phranque
Will it work?
RewriteBase /
RewriteCond %{HTTP_HOST} !^subdomain.mydomain.com$ [NC]
RewriteRule ^(.+)P(.*)\.html$ pt-br/$1P$2
Usually (In 99% cases), the URL only contains one capital letter P.
So that:
aboutusP.html goes to pt-br/aboutus
courseP-20090501.html goes to pt-br/courseP-20090501
Thanks !
If a URL-path that contained an uppercase P was requested from the main domain or any subdomain other than "subdomain.example.com", then the rule would create an infinite loop, because it rewrites xyzPabc to itself -- note the uppercase P in the RewriteRule's substitution.
I'd suggest:
RewriteBase /
RewriteCond %{HTTP_HOST} [b]^s[/b]ubdomain\.example\.com [NC]
RewriteRule ^([^P]*)P([^.]*)\.html$ pt-br/$[b]1p$[/b]2 [L]
However, your first sentence above talks about "html files" so it is possible that you've got the entire RewriteRule backwards.
As documented [httpd.apache.org], here is how a RewriteRule is specified:
# Internally Rewrite requests for requested-URL to internal filepath "new-filepath-or-URL"
RewriteRule requested-URL new-filepath-or-URL [[i]flags[/i]]
Which one of those is the URL used out on the web, and which one is the name of the file stored inside the server?
A rewrite accepts a URL request as input then fetches a file from the server to service that request. Rewrites does not 'make' URLs.
Or is this a case of redirecting requests for an old URL to a new URL? Though you did say "rewrite" in the question, so I guess not.
I am guessing that the original example is worded exactly backwards from what is really required.
Hi g1smd,
courseP-20090501.html is a static HTML files.
I am migrating the entire site (all static HTML files) to a Drupal site. pt-br/courseP-20090501 is a URL alias (through Drupal's per node path setting). Internally, it is node/123. pt-br is a language prefix.
Thanks,
In that case, your code in the very first post is exactly backwards.
However, you also need a redirect so that people asking for the old URL, are redirected to the new URL. That redirect should force the domain name and use the [R=301,L] flags.
A URL is what you see in your browser's stats line when you hover over a link on one of your pages.
A file is a physical file on the server.
URLs are not at all the same thing as filepaths, and are only "associated," not "equivalent."
URLs are used "out on the Web," while filepaths are used "inside your server," and these two "realms" are very different. The basic job of a server is to convert HTTP client-requested URLs to internal filepaths, so that it can find the content that is being requested.
If you click a link to the URL "http://example.com/privacy" on a Web page, then the example.com server may get the file to serve that request from a file-path like "/apache/users/ex/example.com/public/www/privacy.html". Obviously, the linked URL does not contain most of the directory-path info needed inside the server, and the server has no need of "http:" once the request has already arrived at the server.
Mod_rewrite allows you to change the URL-to-filepath association even more; For example, you could add a rewrite so that requests for URL "http://example.com/privacy" would be served with a file at "/apache/users/ex/example.com/public/www/some-new-subdirectory/new-privacy-policy.html".
Hopefully, this clarifies the very-important difference between a URL and a filepath.
Please post an example of one of the "uppercase P" links on your pages, and an example of the filepath that you wish that request to resolve to, including all subdirectory path information.
Jim