![]() |
|
![]() | ||
|
Subject:
URL mapping with Apache
Category: Computers Asked by: charro2000-ga List Price: $10.00 |
Posted:
13 Oct 2005 15:58 PDT
Expires: 12 Nov 2005 14:58 PST Question ID: 579979 |
Hi, I would like to show my URL links as always ending in '.html' but I want to map those URLs to a specific path and file type. Lets say, for example: Steps ----- 1. User submits to http://example.com/login.html 2. The server receives the request and it 'knows' to forward the request to http://example.com/login.php 3. The script is executed and a new page is generated. 4. The user receives a new page and on her browser she sees http://example.com/accountHome.html 5. For a second request, the server receives http://example.com/accountHome.html?search=contacts&lastname=brown and it forwards it to http://example.com/accountHome.php?search=contacts&lastname=brown I would like to have at least a clear summary of what is used in these cases (i.e. using mod_rewrite, mod_proxy, ...) and not just a list of links. I'm looking for a list of general steps to achieve this configuration. What I would find valuable are your comments based on experience for any special conditions or bugs. Environment: Apache/2.0.54 (Win32) PHP/4.4.0 |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: URL mapping with Apache
From: adrianc-ga on 14 Oct 2005 08:56 PDT |
Hi, a simple step to solve the 5 points: Try with this sentence at httpd.conf file after <VirtualHost *> directive RedirectMatch (.*)\.html$ $1.php With this directive, if exist or not the .html file, always it will be redirect to the .php file. I hope it'll be helpful for you. |
Subject:
Re: URL mapping with Apache
From: charro2000-ga on 14 Oct 2005 13:00 PDT |
Thank you for your comment <b>adrianc-ga</b> I tried RedirectMatch but it only worked going one way: 1. I typed example.com/myTest.html and it did call example.com/myTest.php 2. But... the url on the browser is then changed to '.php' I would like that my urls still show '.html' when receiving a response from the server. So I suspect we got half of the problem solved. Could it be that this is where that magic with mod_rewrite or mod_proxy comes in? |
Subject:
Re: URL mapping with Apache
From: anoopshukla-ga on 15 Oct 2005 06:05 PDT |
Yes surely. RewriteEngine On RewriteRule (*)\.html$ $1.php hope it helps. |
Subject:
Re: URL mapping with Apache
From: anoopshukla-ga on 15 Oct 2005 06:07 PDT |
sorry for the mistake, its RewriteRule (.*)\.html$ $1.php i missed the '.' in (.*) |
Subject:
Re: URL mapping with Apache
From: charro2000-ga on 15 Oct 2005 13:29 PDT |
Thank you anoopshukla-ga!! That did the trick. I updated my httpd.conf by doing the following steps: 1. The loading of mod_rewrite is commented out on a default Apache install, so I made sure to remove the '#': LoadModule rewrite_module modules/mod_rewrite.so 2. Then on my virtual host block I added the lines you provided: NameVirtualHost * <VirtualHost *> ServerName example.com ServerAlias *.example.com DocumentRoot "C:/apacheroot/example.com" RewriteEngine On RewriteRule (.*)\.html$ $1.php </VirtualHost> |
Subject:
Re: URL mapping with Apache
From: charro2000-ga on 20 Oct 2005 09:38 PDT |
I just wanted to add that the above solution has one side effect or "feature": - The server will only deliver php files (rewritten as html) but will ignore (as in 404) real html files. What I did was to rename the files (ren *.html *.php) for now. That solved the problem but I suppose it would require a little more tweaking on the rewrite rule. Cheers, SV. |
Subject:
Re: URL mapping with Apache
From: tomclegg-ga on 10 Nov 2005 17:35 PST |
If you add a RewriteCond directive like this, the RewriteRule will be invoked only in cases where the .html file doesn't exist: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*)\.html$ $1.php |
Subject:
Re: URL mapping with Apache
From: charro2000-ga on 14 Nov 2005 13:14 PST |
Thanks tomclegg-ga. But I'm sorry to say that it did not take effect on my server. After adding the rule I added two files with the same content sample1.html and sample2.php The file Sample2.php loaded with no problems, like before and I got a 404 for sample1.html. /Weird |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |