Hiya. I am experimenting with a PHP program I'm writing. I'd like to
have the PHP pretend to be a directory.
I've managed to work out...
example.com/myprog.php/hello
and
example.com/myprog/index.php/hello
But I'd like...
example.com/myprog/hello
(Much like wikipedia does.)
I've done some searching but I can't find how to make it happen. Anyone
know the magic words please?
LGK 7 1751
Louise GK schrieb: Hiya. I am experimenting with a PHP program I'm writing. I'd like to have the PHP pretend to be a directory.
The magic words are mod_rewrite and this is an apache module. By that, you
can have a "frontend" URL like /hello which is then rewritten to a backend
one like "index.php?page =hello".
Then you can have the php script handle the options as usual.
HTH
Fred
Louise GK wrote: Hiya. I am experimenting with a PHP program I'm writing. I'd like to have the PHP pretend to be a directory.
I've managed to work out... example.com/myprog.php/hello and example.com/myprog/index.php/hello
But I'd like... example.com/myprog/hello (Much like wikipedia does.)
I've done some searching but I can't find how to make it happen. Anyone know the magic words please?
If you're on Apache you can either use mod_rewrite or set the
application type like so:
mod_rewrite:
RewriteEngine On
RewriteRule ^/myprog/(.*) /myprog.php?foo= $1
application type:
<Location /myprog>
ForceType application/x-httpd-php
</Location>
In the case of setting the application type you'd create the php script
without a filename extension (ie so it's just called "myprog"). I
personally prefer to use mod_rewrite but have used the other method in
the past.
If you're not using Apache... well you'll have to look for another
solution. There's 3rd party addons for IIS which work like Apache's
mod_rewrite but you generally have to pay to use them.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Louise GK wrote: Hiya. I am experimenting with a PHP program I'm writing. I'd like to have the PHP pretend to be a directory.
But I'd like... example.com/myprog/hello (Much like wikipedia does.)
Besides the earlier suggestions, another route to explore is the Apache
directives:
DirectoryIndex
so you can do http://example.com/progDir instead of http://example.com/progDir/index.php
and AcceptPathInfo
so you can do http://example.com/progDir/index.php...t/looks/pretty
But really, what you'd like is a combination so that you can then
write: http://example.com/progDir/fake/dirs/so/it/looks/pretty
In other words, Apache should figure out the longest directory that has
a file that it can use DirectoryIndex on, and then use that, with the
remaining portion being the PathInfo part (this PathInfo by the way, is
passed into PHP)
This was not working a few years back, but the response to my bug
report after an enthusiastic reception was that it would be too hard to
fix. Haven't checked the current situation.
Good luck,
Csaba Gabor from Vienna
Louise GK wrote: Hiya. I am experimenting with a PHP program I'm writing. I'd like to have the PHP pretend to be a directory.
I've managed to work out... example.com/myprog.php/hello and example.com/myprog/index.php/hello
But I'd like... example.com/myprog/hello (Much like wikipedia does.)
I've done some searching but I can't find how to make it happen. Anyone know the magic words please?
Many people, many opinions...
My opinion:
Place the phpfile in the web-root, call it myprog.php and enable MultiViews
on the dir: http://httpd.apache.org/docs/1.3/con...gotiation.html
Then you can access the file with example.com/myprog/whatever/you/want
Works like a charm...
--
MVH Jeppe Uhd - NX http://nx.dk
Webhosting for nørder og andet godtfolk
Chris Hope schrieb: If you're on Apache you can either use mod_rewrite or set the application type like so:
(...) application type: <Location /myprog> ForceType application/x-httpd-php </Location>
In the case of setting the application type you'd create the php script without a filename extension (ie so it's just called "myprog"). I personally prefer to use mod_rewrite but have used the other method in the past.
In fact, you should avoid this if possible. It's quite "dirty" as you
can't see that it's a php file anymore and you have to do this for every
location you want to use. Mod_rewrite is much more flexible.
There are servers that don't have it enabled though. In this case I can
see why you used it.
Bye
Fred
Frederic Wenzel wrote: Chris Hope schrieb:
If you're on Apache you can either use mod_rewrite or set the application type like so:
(...) application type: <Location /myprog> ForceType application/x-httpd-php </Location>
In the case of setting the application type you'd create the php script without a filename extension (ie so it's just called "myprog"). I personally prefer to use mod_rewrite but have used the other method in the past. In fact, you should avoid this if possible. It's quite "dirty" as you can't see that it's a php file anymore and you have to do this for every location you want to use. Mod_rewrite is much more flexible.
Which is part of the reason I don't use it anymore. When I first started
using that method I don't think I was aware of mod_rewrite
There is another method I have used which allows you to keep the
filename extension on the original file, using aliases, and you can
still make it "look like a directory":
Alias /foo /path/to/foo.php
There are servers that don't have it enabled though. In this case I can see why you used it.
I've always hosted the sites I do this sort of stuff on on my own
servers, or servers I manage. But as I mentioned I wasn't originally
aware of mod_rewrite or the power and flexibility you have with it. The
other nice thing with mod_rewrite is you don't have to bother writing
code to parse the uri.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Chris Hope wrote: mod_rewrite: RewriteEngine On RewriteRule ^/myprog/(.*) /myprog.php?foo= $1
Once I worked out that this was for the .htaccess file and not the PHP
code, it worked. I ran it against a myprog.php which just contains a
call to phpinfo(). I visited http://example.com/test/myprog/bar to
produce a variable $PATH_INFO containing "/bar". Excellent.
I experimented with dropping the "?foo=$1" part and that produced
example the same result. With that, I experiemented to see if the ( and
) were only needed for the $1. That worked, so I now have this file as
"~/example.com/htdocs/test/.htaccess".
php_flag register_global s off
RewriteEngine On
# RewriteRule ^/myprog/(.*) /myprog.php?foo= $1
RewriteRule ^/myprog/.* /myprog.php
Which is working perfectly, as checked with http://example.com/test/myprog/bar?C...rGlobals=IsOff
$PATH_INFO == "bar"
$_GET["CheckRegisterG lobals"] == "IsOff"
$CheckRegisterG lobals does not exist.
Thanks. (hug)
LGK. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bbxrider |
last post by:
for win2k adv server/iis5.0
trying to run an external program from my asp routine that has multiple
parameters, see following
set shell = server.createobject("wscript.shell")
shell.Run """f:\phsData\htmldoc\htmldoc.exe"" --webpage -f phsnew.pdf
phsnew.htm"
program either doesn't get invoked, or has an error, but since it has no
error log i can't check that,
|
by: Wysiwyg |
last post by:
Is there any way to add an embedded resource to a project without copying it
to the project's directory? I have shared resources and don't want each
project using the images, xml files, etc. to need to be updated with the
current copy before being built. I also don't want projects being built with
the old copy.
Thanks!
Bill
|
by: et |
last post by:
This might be more of a visual studio question, or maybe even an iss
question, but I couldn't find a newsgroup for just visual studio, and my
project is an asp dot net project.
I made backups of my projects usually at particular milestones, and
sometimes I need to go back and review what I did in certain circumstances,
such as a procedure or something that has since been removed. Yet I can't:
the directory is now labeled bk1Project and...
|
by: lucifer |
last post by:
hi
i am making an http server
it has following functions
main()
{
if option is "-?", output the hints and stop
check the directory supplied is sensible and not a security risk
become a daemon process
ignore child programs (to avoid zombies when child processes stop)
|
by: yenra |
last post by:
Can anyone help me in making this program?!...
I need to make a telephone directory using structure definition..
typedef struct AddressTag{
char surname;
char givenname;
char middleinitial;
char telnum;
struct PersonTag *next;
| |
by: Justin Fancy |
last post by:
Hi Everyone,
I am developing a file aging program that will eventually report on
every folder that is in the root directory. I have a list of requested
years, and counters set up to count every file within every subfolder
to add up all the files from the specified year. I have the
functionality working, but not quite. With the following code, the end
result includes folders within subfolders. For example, instead of
having root/folder1/...
|
by: Ron |
last post by:
I would like to write a small program to manipulate this XML:
http://www.keepitsimplekid.com/xml/Ad00304.xml
What I want the program to do.
it would look at all.xml documents in a directory for example
directory C:\XML\rename
A Rename button would be pressed on the form and the program would go
|
by: Gurpreet Singh |
last post by:
hi everyone,
i want to create a folder on the harddisk using c program.
the folder is infact a nested folder like sec1\subsec22\subsec9
to be created in c:\ drive.
I tried the following statement
mkdir ( c:\\sec1\\subsec22\\subsec9);
but it does not work.
the 'system' command system("md sec1\\subsec22\\subsec9")
is also not working.
|
by: C#_Help_needed |
last post by:
I need help with the following question. THANKS :)
Write a program in c# that takes in a directory as a command line
parameter, and returns the longest repeated phrase in ALL text files
in that directory. Assume that all contents of all the files may be
held in memory at the same time. Do not use unsafe code blocks and/
or pointers.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |