Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Does Mod Rewrite Change PHP_Self?

Posted on 2006-06-23
7
Medium Priority
?
595 Views
Last Modified: 2012-06-27
If I use mod rewrite to fake .html endings on my php files (i.e. the URL discussion/viewpost=15.html calls the script otherwise located at discussion.php?viewpost=15), and then use $_SERVER['PHP_SELF'] to determine the current URL, will it give me the URL that was typed into the browser window (or clicked on), or the one that is actually being called on the server? In otherwords, will it return discussion/viewpost=15.html or discussion.php?viewpost=15 ?

Normally I would just go and test something like this, but I haven't figured out how to use mod rewrite yet, and I want to know how it is going to affect my scripts once I implement it.
0
Comment
Question by:jfredrickson
  • 5
  • 2
7 Comments
 
LVL 21

Expert Comment

by:Julian Matz
ID: 16976977
I think PHP_SELF will return the real URL.
I'll test this now to confirm...
0
 
LVL 21

Accepted Solution

by:
Julian Matz earned 2000 total points
ID: 16976983
Yes, it returns the real URL.

For example if
index.html --> redirects to --> index.php
and /index.html is entered in the browser, PHP_SELF will return /index.php.
0
 
LVL 4

Author Comment

by:jfredrickson
ID: 16977010
Awesome. And if I understand correctly, Mod Rewrite doesn't actually redirect in the sense that javascript does by actually forwarding the browser, but simply display a different page right? So in reality, the user types in index.html, the server displays index.php, PHP_SELF returns /index.php, and the URL in the browser bar remains only displaying index.html as if it is just another HTML page. Is that right?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 21

Expert Comment

by:Julian Matz
ID: 16977027
Yes, that's correct :)

And index.html doesn't actually need to exist for it to work.
But you can use mod_rewrite to actually redirect the page if you wish. The example below would do a valid permanent redirect and send a 301 status code to the browser (or search engine):

RewriteEngine On
RewriteRule ^viewpost([0-9]*)\.html$ /index.php?viewpost=$1 [R=301,L]

The "R" flag will cause the page to redirect and the "=301" will cause a permanent redirect (the one you should always use to keep search engines happy).

If you just want to rewrite the URL without the redirect, you can simply leave out the "R" flag...
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 16977044
I just wanted to add that you don't need the 301 redirect when using mod_rewrite to keep search engines "happy" because a rewrite will be transparent to the search engine anyway... I just mentioned it before in comparison to javascript or normal php redirect...

To redirect a page using php, you could do:

<?php
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://www.example.com/newpage.php');
header ('Connection: close');
exit;
?>

The above will work on search engines and also on browsers that have javascript disabled...


I've rambled on a little now :) If any of this doesn't make sense, please let me know...
0
 
LVL 4

Author Comment

by:jfredrickson
ID: 16977048
Wow, I am getting more than I had asked for here. I am going to accept your first answer because that really answered my question, and rather than getting more answers for other questions on the same 500 points, I opened up another question so that you can help me with the Rewrite stuff.

I am not 100% sure that this is the correct protocol for this site, but it is my understanding that we are only supposed to ask 1 question at a time so that experts recieve points for every question they answer.

Anyway, here is the link for the new question. If you reply there I can give you points for your help with the Rewrite stuff too.

http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_21898173.html

Thanks for the awesome help.
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 16977086
Thanks for the A, jfredrickson! Glad I was able to help...

Yes, that is the correct protocol... I wouldn't have minded answering your question here at all, but appreciate the points also :)

-Julian.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

971 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