PHP is running inside server1. Documents(.xls,.doc) available inside server2.
When I am redirecting to document path from php code (available at server1) the url becomes like this
server1<path>/server2/<documentname>
But I want to open url from php code is like this
server2/<documentname>
I dont want to include server1 path as prefix.
Is this possible in PHP?

Not sure what you asking for, provide your code. Anyway you could use mod_alias module in Apache:

That way you can return data from from server2 without actually seeing it, for example set this in server1 config file:

Alias /remotefiles http://server2.tld/files
<Location /remotefiles>
    Order allow,deny
    Deny from all
    Allow from 192.168.0.10
</Location>

Where the 192.168.0.10 is server1 IP. That way your scripts can access to those resources just by using:

$_SERVER['DOCUMENT_ROOT'] . "/remotefiles/some.doc"

You should put a similary rule in server2 to allow access only from server1:

<Directory /files>
    Order allow,deny
    Deny from all
    Allow from 192.168.0.10
</Directory>

If instead you want to enable public access then change the above rule to:

<Location /remotefiles>
    Order allow,deny
    Allow from all
</Location>

But I think this is the reverse of what you want. So explain better or provide some code. Bye.

myapplication is folder name inside htdocs.

localhost/myapplication/itemslist.php?showmaster=Product_list&PARENT_ID=2

This PHP page contains a link like this

<a href="\\srv01\CDS\ITEMS\ITEMLIST.xls" target="_blank">document</a>

ITEMLIST.xls document is available at srv01 server(srv01 and localhost are two different servers).
When I click on document link the url becomes like this

http://localhost/myapplication/\\srv01\CDS\ITEMS\ITEMLIST.xls

But requirement is, when user clicks document link the url should be

\\srv01\CDS\ITEMS\ITEMLIST.xls

That path seems an intranet resource (UNC) rather then a web server. Can you confirm that? In this case I cannot help, I don't have much experience on Windows systems, so wait for help from Windows users.

I think that the resolution of the UNC link depends on the client, so if it cannot see the segment of lan with that resource, it will not be able to access to the file.

If the files, instead, are served by a webserver then you need to change the path \\srv01\ to http://srv01/ and convert the backslashes to slashes, so \ to /

This:
\srv01\CDS\ITEMS\ITEMLIST.xls

Becomes this:
//srv01/CDS/ITEMS/ITEMLIST.xls

Example:
<a href="http://srv01/CDS/ITEMS/ITEMLIST.xls" target="_blank">Item List</a>

If your servers have static IP addresses avoid using hostnames as this will allow the link to continue working even if DNS fails or the host name is changed in the future.

<a href="http://srv01/CDS/ITEMS/ITEMLIST.xls" target="_blank">Item List</a>

This is giving error

Unable to determine IP address from host name "srv01"
The DNS server returned:
    Name Error: The domain name does not exist.

Do you currently have access to srv01? Are you able to get a response from the server? Have you used its IP address as recommended rather than its hostname?

I have access to srv01. when I type \srv01\CDS\ITEMS\ITEMLIST.xls from address bar document will be downloaded. I cannot use ipaddress. This is the requirement.

Okay I wasn't aware of your requirement. Could you not atleast get the IP from the hostname and use the IP? I have a thing for using IP addresses in links :3

$ipAddress = gethostbyname('http://srv01');

What web service is currently running on srv01? Apache, IIS or? Are you going through any firewalls or proxies?

I got ipaddress from administrator. When I try

http://ipaddress/cds/

giving Access denied error.
But trying like this \ipaddress\cds\ from browser address bar, it converted into

file://///ipaddress/cds/

and showing list of files.
When I am doing this redirection from php code the url becomes modifying like this

http://localhost/myapplication/\\ipaddress\cds\

I want to redirect only \ipaddress\cds\
simply my requirement is opening remote server location from php webroot of another server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.