I currently have: www.MYPAGE.com/category (a site I reach from my shop site)
But I want: www.MYPAGE.com/shop/category (so the subpages kinda stack)
So how do I actually achieve that ? Working with .htaccess or a more simple way ?
if you want .htaccess
# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
but you can use framework route if you use one
I'm assuming you're not using a CMS (Wordpress ect) and are just using plain old html.
To change the URL structure simply change directory structure.
So for example put your category index.html file in the directory /shop/category/ and the hyperlink to that page is now www.MYPAGE.com/shop/category/
Can't comment yet, so I'll risk a bad answer.
Up front, it's been a while since I used php (php4). But we never used php without some other software, usually Apache, to actually serve pages.
A quick check on the php and pear documentation sites doesn't show me that the situation has changed much.
Therefore, I'll start with the simplest description I can remember.
Your server machine runs an OS. You have a web server such as Apache, Nginx, Microsoft's IIS, lighttpd, etc., fielding queries from the web in http protocol. (Skipping discussion of https, look that up later.)
If we were using Apache's httpd, there would be a configuration file for Apache, usually called httpd.conf. In a Linux or Unix environment, this is usually under /etc/(somewhere) in the file system. In that file, you would have a declaration of the document root directory.
Unless you add other configurations, the directories under the declared document root are available to the web as they are in your file system. So, if the document root is set as /var/www and your your domain name (which is a separate topic I assume you are not asking about) is set up as in your example -- www.MYPAGE.com, then the file
/var/www/aboutus.html
would be available on the web as
www.MYPAGE.com/aboutus.html
and the directory
/var/www/shop/
would be available on the web as
www.MYPAGE.com/shop/
Apache allows you to redefine that structure with configuration directives such as Alias and ScriptAlias. Script configurations are the basics for hooking php into your httpd server. Apache's configurations for those can be found from their documentation page on url mapping, which you can find through the links above. (I don't have enough cred to post more than two URLS, sorry.)
You might want to look at virtual hosts (vhost) as well, but focus on Aliases for now.
Say you have product photos in
/var/app/products/photos
You could have an Alias like this:
Alias "/shop/images" "/var/app/products/photo"
and (if I remember right and if you don't have locations and url re-writing set up) they would be available on the web at
www.MYPAGE.com/shop/images
And, since I don't have enough cred to post more links, that's as far as I can go with this. Take a quick look at mod_rewrite in the httpd documentation.
Then look in the php documentation for related configuration directives, and it should take you maybe a day of practice at most to understand the basics.
Do get your boss or teacher to allow you to use the time and hardware to practice. Otherwise, your productivity will be stuck in the mud.
Related
I have been trying to understand a way to run PHP within .html in my server 2019. If there is a way to do so? can someone give me some guidance on it?
There was a post on this already How to run php code in html file on windows server?, but it does not seem to be much help.
Thank you for the help!
You cannot execute PHP code in html, you can do that only in .php file with the help of a web server.
You can have an ajax call that will interact with a url (which can be a PHP file resource) and that can return some processed result.
.php file can have html and it will work all fine but you need a web server to run the .php files. You can install wamp/xampp on your windows server and use that to do some processing using your .php file.
I'm not 100% sure why you would do this, .htm and .php files are both common on the internet. You either have to provide a full link containing the file type or perform some sort of rewrite to remove the extension for end user simplicity and this process would be fairly similar whether its .htm or .php youre dealing with.
To answer the question though, i havn't personally done this, but the link you provided implies it should be possible. What they're talking about is adjusting the "Handler Mappings" in IIS. This can be done at two levels, either at Webserver level or Website level. If you open Internet Information Services Manager (assumes you root access to the windows server and not just access to upload a website, if you don't the server admin will need to do this!) you will get a tree down the left side called "Connections". Under Connections either:
Click the PC Name (a server with a globe icon) for server level
Or
Click the website (just a globe under the sites folder for site Website level)
Then you need to find the Handler Mappings on the main window under IIS > Handler Mappings.
they are then suggesting creating a mapping for .htm and .html that follows the same rules as the .php mappings. I would read up on this page and what it does though.
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/
A couple of things to note:
You may have to install PHP yourself using the Web Platform Installer as i recall it's not there by default on all (if any) versions of IIS. Until you do this you may not see the PHP handler mappings mentioned in the above section.
you will likely need a mapping for .htm and .html separately.
.htaccess files dont work in IIS, you usually have to find a web.config equivalent, i suspect you wont find one for this though due to how IIS works.
If you dont own the server or all of the sites on it, you may wantr to do this at website level first to make sure it doesn't break any of the other sites.
Is there a way to dynamically find a user's cgi-bin path using PHP and write a file to it?
For instance, I want to write a PHP application that also uses a Perl script for additional functionality (will not break without it), and on first run I want to get the path for cgi-bin or whatever the user's directory is named, and write the script into the directory so that it can be invoked by the application, with minimal installation required by the user (i.e. upload application to a directory, then run index.php).
Is this possible? Or am I dreaming far beyond what I can actually do?
The simplest solution I see to this would be to use a regex to check for a directory named /cgi/ starting at the user's root directory, however, this doesn't seem like an entirely reliable method
__FILE__ gives you under both Perl and PHP the name of the currently executed file.
There is no sane way.
A server can be configured to execute CGI programs in zero, one or many different locations, none of which have to have "cgi" in the name.
You could try parsing the server configuration to identify which (if any) locations are set up that way, but you would have to write a separate parser for each server, and each one would be very complex. Even if you limit things to Apache, then you would have to deal with filtering based on virtual hosts, <file>, <directory>, <location>, ScriptAlias, .htaccess, etc.
I noticed that most of the frameworks (CodeIgniter for example), do provide a default .htaccess file but don't force its use.
Why don't they force its use?
Does .htaccess work on all servers?
What are the alternatives?
.htaccess files only work on apache servers. When using other servers it highly depends on what you want to do - but usually you need to edit the server config to rewrite URLs, block directories, etc.
The fact that frameworks need .htaccess files is actually an annoying problem from the PHP world since 99% of all applications are stored inside the document root, thus giving users HTTP access to all their files unless they are somehow restricted (e.g. via .htaccess). On the other hand, if you have a WSGI-based python application, you usually store it outside the document root and "mount" it to a certain folder in the document root - this way not a single file can be accessed directly via HTTP.
1) I have to agree with Juhana. The question is: why should they force it? There is no need to restrict a framework with such a thing.
2) I heard that they are not working on IIS Server, where you have to translate it in special config files.
3) It depends on what you're doing. But because of the fact you do not really need .htaccess files, just let them be is a possible alternative :)
Because it does not work on all servers (esp. hosting providers can restrict its use) and there is really no good reason to enforce it.
See #1. Also, they tend to not work in the same way if you're not running Apache.
Very wide question. If you're running Apache it's pretty much the only way to configure the server while not being a privileged user. If you're not running Apache, it's dependent on the specific web server.
Some useful links;
Apache htaccess to nginx rewriterule converter
How to translate htaccess to IIS web.config
How to work around lighttpd's lack of directory specific config
I had a terrifying issue a few days ago. I was installing updates on my ubuntu server, which is a hosts for about 10 websites. During the update, something went wrong, and apaches mod_php became disabled. As a result, PHP support was gone, and for a few minutes (until I figured what's wrong) users got an invitation to download PHP scripts, instead of seeing a website. Needless to say, there is nothing worse then exposing your script sources to the whole world, especially when database credentials are kept inside.
The question: How can I configure apache, so this situation would not be possible in the future? What lines should I add to apache2.conf, so that PHP files could not be downloaded, if mod_php is disabled?
Just add the following to the .htaccess in the root directory
php_admin_flag engine on
In this case user will get HTTP 500 error trying to read any file from this dir and below because no module defines php_admin_flag directive in case mod_php is off.
A more secure approach would be simply to not put things you don't want accessed in the document root in the first place. See my answer here which provides more detail; the basic idea is, if you don't ever want a file accessed via URL, don't put the damn file in a URL accessible place. 99% of your app code should not be under the document root; then it doesn't really matter what you do to your apache/php setup, you're still safe.
I would like to be able to port some new site pages over to PHP using the same db as in the coldfusion site. Is it possible to have PHP run pages in say other directory and go back and forth ?
Many thanks for your reply.
Terry
As others have said, yes, it is possible. Your configuration doesn't really matter, (unless you're looking for help getting it setup), because it can be done on any modern webserver (Apache, IIS, etc).
Something to think about, though, is the default document. If your web application uses urls like:
http://example.com/myApp/ (no index.cfm or index.php in the url)
Then you need to be aware of the explicit order of default documents. If you have both an index.php and an index.cfm template in the same directory, which will execute?
If your default document list is (a variation of):
index.cfm index.php default.aspx index.html
Then the ColdFusion page will be the one to execute. On the other hand, if the default document list is (a variation of):
index.php index.cfm default.aspx index.html
Then the PHP page will be the one to execute.
Yes, this is possible, I have this available on my production web server (RedHat but it shouldn't matter). If you're looking for details on configuration I couldn't help you though, I had my host set it up. I wouldn't imagine a standard install of both would conflict, just set up the proper handling for each file extension and you should be good to go, keeping them in separate directories or mixing them in one.
It is possible as long as you are running the same web server (i.e. IIS or Apache) for both ColdFusion and PHP. If you let us know what your environment is, people may be able to further assist you - but the answer to your question is yes.
Yes,
It's technically no different to Windows servers which have both PHP and .Net installed, or a Linux server with Perl and PHP.
Speaking generally, after installing the languages you're using you set up your web server to handle files of different extensions. This is done differently depending on whether you're using IIS or Apache, but you effectively say .php files should be handled by the PHP interpreter and .cfm files handled by the Coldfusion interpreter.
As others have said, its entirely possible and not hard to setup. Just watch out for Default Document as Adam Tuttle said.
I will take it a step further: you even run CF and PHP in the same application server!
Use Cauchos Resin for CF and its Quercus support for PHP:
http://quercus.caucho.com/
Of course, if your PHP app is non-trivial and/or relies on some custom extensions or extensions that Quercus doesnt support than your SOL. But might be interesting to check out.