Reputation: 3690
I have made some changes to a clients website.
The client was continually being attacked using SQL injection, and at the moment the URL contains variables that the website needs (i.e. index.php?filenmae=home.php).
So after securing the site as best I could using mysql_real_escape_strings
and stripslashes
, I then came to do URL rewriting in Apache.
At the moment, the server the website is currently on doesn't support mod_rewrite (i've checked using phpinfo) and it's not a server belonging to us. Is there anything I can do in my .htaccess file that would enable mod_rewrite for this website?
Upvotes: 1
Views: 7963
Reputation: 1
For Shared Hosting Server , It Really Work.
.htaccess
in your site's root folder.RewriteEngine On
.RewriteBase /
.Upvotes: 0
Reputation: 14946
Mick, the best solution for you is to change your code. I'm guessing that in your code you then include the filename specified, e.g.
include $_GET['filename'];
In short, there is no way using mod_rewrite
that you can make this secure.
However, you can make it more secure very easily by checking that the filename is valid, e.g.
$valid_filenames = array('home.php', 'foo.php', 'bar.php', /* etc... */);
if (!in_array($_GET['filename'], $valid_filenames)) {
echo "Invalid request.";
exit;
}
include $_GET['filename'];
Just make sure that you validate the requested filename before including it and you'll be much better off.
Upvotes: 1
Reputation: 168695
If mod_rewrite is installed, you can configure it in your local .htaccess
file.
.htaccess
in your site's root folder.RewriteEngine On
.RewriteBase /
.If it isn't installed, you're out of luck - no web host will install extra software on a shared hosting box just for one client.
Upvotes: 2
Reputation: 66425
No, you cannot dynamically load mod_rewrite. Most hosting providers have mod_rewrite enabled on Apache servers. If they do not, you could ask them for enabling it. Otherwise, if you really need mod_rewrite, consider switching hosting providers.
As an alternative, you can rewrite URL's in PHP.
$_SERVER['QUERY_STRING']
can be used for getting the part after the question mark (http://example.com/file.php?this_part)./
, ;
) using explode('/', $_SERVER['QUERY_STRING'])
$_GET
with an empty array, and put the newly generated values in it.
Note: filter_input
and related functions do not operate on $_GET
. Thus, this method will not work for filter_input
.Upvotes: 0