0

My .htaccess works (not an expert, but do a lot of copy & paste).

A typical rewrite for one of my pages looks like this:

RewriteRule ^my-grills-parts-and-service/?$ parts-service.php [NC,L]

...where the url "http://www.mydomain.com/my-grills-parts-and-service/" will invoke the parts-service.php file.

However, I am using php to construct a fully qualified URL, from what is in the address bar. The problem is, the server variable $_SERVER['SCRIPT_NAME'] will return "parts-service.php", rather than what is actually in the address bar, "my-grills-parts-and-service/".

I want php to somehow read the literal rewrite string, rather than the actual filename.

So, I want php to construct a string like this:

$url = "http://www.mydomain.com/my-grills-parts-and-service/";

I hope I don't have to write a data table or switch or if block, because that would be doing everything twice (once in the .htaccess, and again in a php file).

TARKUS
  • 2,170
  • 5
  • 34
  • 52

1 Answers1

2

You can use $_SERVER['REQUEST_URI'] to get real url address.

Before using this method, check @regilero comment.

Elon Than
  • 9,603
  • 4
  • 27
  • 37
  • Yep. I think this is the answer. I'll give it 24 hours before selecting as best answer. Works great for what I am doing. - G. – TARKUS Sep 13 '13 at 09:03
  • 1
    @Gregory Lewis : Beware that you should escape $_SERVER['REQUEST_URI'] before using to build HTML content, avoid users injection HTML/js in the url. Check http://stackoverflow.com/a/326331/550618 for details on SCRIPT_NAME vs REQUEST_URI – regilero Sep 13 '13 at 15:54