2

HI im trying to develop a MVC pattern through a website , from the beginning I need to get url I tried like this

echo $url= $_GET['url'];
echo $url;

If i use a url like this http://localhost/autolink/index/sdsad it wanna show "index/sdsad" but its not showing anything, what can be wrong on this? can be a version problem? coz used in a another machine it was working..

This is my current .htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
sberry
  • 128,281
  • 18
  • 138
  • 165
Wazan
  • 539
  • 1
  • 8
  • 27

2 Answers2

4

If that url was working on another machine then you had some sort of rewrite rules in place. You likely had something like:

RewriteEngine On
RewriteRule ^autolink/.* autolink.php/?url=$0 [QSA,PT]

This would make the index/sdsad get passed in as a url argument in the query string.

Your example works for me and implies that you either

  1. Don't have mod_rewrite turned on
  2. Don't have Allow Overrides turned on

Easiest way to check (assuming this is not a production server) is to edit the .htaccess file and put in something like "POOP" on the first line. If you start getting 500 errors, then 1 and 2 above do not apply.

sberry
  • 128,281
  • 18
  • 138
  • 165
  • I added your comment to your original question. – sberry May 01 '12 at 05:43
  • 'RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]' – Wazan May 01 '12 at 05:44
  • Im not geting any 500 error, rest of the things on that page working perfectly. only echo $url= $_GET['url']; not showing – Wazan May 01 '12 at 05:49
  • Thank you very much its working now... I didnt do anything.. the problem on Browser. Thanks ALOT sberry – Wazan May 01 '12 at 05:58
  • Now I can get url from echo $url= $_GET['url']; but when I use http://localhost/autolink/index/sdsad index is not showing let say if i use othe than index then its working , http://localhost/autolink/notindex/sdsad .. why is that? – Wazan May 01 '12 at 07:20
0

I develope PHP projects with Visual Studio 2019 Community by using PHP Tools for Visual Studio 2019 and IIS. I got the same problem during testing MVC patern and instead $_GET['url'] which did't work started to use $_SERVER['REQUEST_URI'].

Sharunas Bielskis
  • 1,033
  • 1
  • 16
  • 25