1

I want to require a PHP File with a get parameter if and only if someone request a URL without any extension like .php and .html etc (i.e. directory) and that directory also don't exist.

For Example : example.com/xyz now there is no xyz directory on server then .htaccess requires a php file with get parameter - myfile.php?url=xyz

  • possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – nickhar Mar 16 '14 at 23:51

2 Answers2

1

but if i request xyz?id=1 it still send only xyz. Is there any way to send whole string no matter what is string

As you mentioned if you request example.com/xyz or example.com/xyz?id=1 you want to get all the parameters. Then use this. Notice the QSA flag. That will append the requested query string. I think this is the answer you're looking for.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myfile.php?url=$1 [QSA,L]

So if you request this example.com/xyz?id=1&h=2

Your PHP print_r($_GET); output will be this.

Array ( [url] => xyz [id] => 1 [h] => 2 )
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
0

start with this snippet

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ myfile.php?url=$1 [PT,L]
    ErrorDocument 404 /myfile.php
</IfModule>
optional
  • 92
  • 6
  • Thank You So Much :) It Works.. but if i request `xyz?id=1` it still send only `xyz`. Is there any way to send whole string no matter what is string? – user3314428 Feb 15 '14 at 21:13
  • you have to write (or find) url parser function. you can only get parameters with .htaccess... xyz here is not parameter, this file name or part of query string... google this "php url parser" – optional Feb 15 '14 at 21:21