Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP mod ReWrite -> Simple Problem

Posted on 2005-03-30
7
Medium Priority
?
252 Views
Last Modified: 2010-03-04
Hi everyone-

I'm a newbie, one of you will probably knock this out in 5 minutes.

I have an .htaccess file, the ReWrite engine is installed. all I want to do is have any requested .php page on my server (i.e. x.php) show up in the URL as x.html.  All the while, the actual file on the server is x.php. So really the URL is just a bogus rewrite.

I appreciate your help with this as it's driving me nuts!
0
Comment
Question by:cjason
  • 3
  • 3
7 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 13669612
Mod_rewrite can only rewrite your request og xy.html internally back to xy.php. Mod_rewrite is not a markup praser, which means that you have to change all links to xy.html in your template output by yourself.
The following in a .htaccess will rewrite a request of xy.html internally to xy.php


RewriteEngine On
RewriteRule ^(.+)\.html$ /$1.php [L]
0
 
LVL 4

Expert Comment

by:TomDavidson
ID: 13670091
Another option is to tell Apache to treat all .html pages as php using the ForceType directive in your htaccess file like:

<Files *.html>
    ForceType application/x-httpd-php
</Files>

This will also require you to make sure all the links are to .html files and not to .php files. Whether this works may depend on whether you have php as a module or php as cgi.
0
 
LVL 3

Author Comment

by:cjason
ID: 13671145
Thanks caterham and TomDavidson for your feedback. I just want to be sure I'm clear on what you have explained.

1) mod_rewrite basically redirects URL requests, but does not "mask" a URL to something it is not.
2) Using an .htaccess file, I've been able to configure the server so that .html files are treated as .php, and will actually execute code.

I'm trying to figure out if this is possible:
I upload xyz.php to the server.
A user requests xyz.php, and all of the PHP code is parsed and served to the user.
Using some kind of global directive (such as in the .htaccess file), the server gives the user the xyz.php file, but the URL is displayed as xyz.html.

It seems to me that this is done on larger sites, such as CNN and ESPN, where clearly there is a lot of server-side action going on, but the end URL that the user sees is plain .html.

So just to confirm--
Is what I'm trying to do with an .htaccess file possible?

Thanks.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 27

Expert Comment

by:caterham_www
ID: 13672677
> the server gives the user the xyz.php file, but the URL is displayed as xyz.html.

If you type in xyz.html and use the rewrite rule in your .htaccess, you should see the content of xyz.php (without knowing that you are on xyz.php), right.
0
 
LVL 3

Author Comment

by:cjason
ID: 13676873
That would require me to go in and change all the links that point to .php files to point to .html files. This is ok if this is the only solution, I'm just trying to figure out if there's a way to:

1) upload a php file
2) I type in a php file to load (xyz.php)
3) The php file loads, but the URL reads xyz.html

No changes would be made to any of the URLs in the HTML code of the actual pages on the server.

Is this possible using .htaccess?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 800 total points
ID: 13680644
This is possible, but it does not make sense in therms of search engine optimazion and hiding that PHP serves the pages. You won't find your website in search engines listed, because you have no incomming links on the files you are redirecting to (xy.html).

RewriteEngine On
RewriteRule ^(.+)\.html /$1.php [L]
RewriteCond %{THE_REQUEST} \.php
RewriteRule ^(.+)\.php /$1.html [R=301,L]


0
 
LVL 3

Author Comment

by:cjason
ID: 13811699
Thanks caterham and TomDavidson for your input. It helped me figure out what I'm looking to do.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question