Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite short url with mysql Query not working

         

nitinp

10:02 am on Nov 17, 2014 (gmt 0)

10+ Year Member



Hello,

I'm writing the custom rewrite rules to generate an seo friendly urls, for that created file into conf folder says k.php and passed the parameters to httpd.conf as fallows but it is not working. Please help me to track this issue.

Old URL: [domain.com...]

New URL Wanted: [domain.com...]

The php file with name is: k.php

-----------------------------------------------------------------
<?php
# PHP/MySQL db connection
$hostname_conn_ht = "127.0.0.1";
$database_conn_ht = "dbname";
$username_conn_ht = "username";
$password_conn_ht = "password";
$conn_ht = mysql_pconnect($hostname_conn_ht, $username_conn_ht, $password_conn_ht);
mysql_select_db($database_conn_ht, $conn_ht);
# this program cannot die ... TO DO: graceful error handling needed
set_time_limit(0);
error_log ('your_content', 3, 'k.log');
# assign STDIN to handler
$keyboard = fopen("php://stdin","r");
# always
while (1) {
# read STDIN to variable from handler
$line = fgets($keyboard);
error_log ($line, 3, 'k.log');
# check for string '/chars/chars/' in URI
if (preg_match('/(.*)\/(.*)/', $line, $igot)) {
$getalias = mysql_query("SELECT id FROM `krd_community_groups` WHERE name = 'mpleague'");
while($row=mysql_fetch_array($getalias)) {
$arid = $row['id'];
print "test\n";
error_log ('test', 3, 'k.log');
}
# print dynamic resource reference to STDOUT (does not refresh URI in address bar)
print "https://www.domain.com/my-team-league/viewgroup/$arid-MPLeague\n";
error_log ('test6', 3, 'k.log');
}

else {
# did not match '/chars/chars/', so just use the original URI (i.e. 'about.html')
print "$line\n";
}
}
?>
---------------------------------------------------------------

Following is the httpd.conf file where i'm trying to making rewrite rules but it don't working help me to work it please.

The htaccess rewrite map is used here and call to the k.php file to getting query results into httpd.conf. please help me to fix this.

httpd.conf

# Include "/opt/bitnami/apache2/conf/ssi.conf"
AddType application/x-httpd-php .php
PHPIniDir "/opt/bitnami/php/etc"
Include "conf/deflate.conf"
Include "/opt/bitnami/apache2/conf/bitnami/bitnami.conf"

# Include "/opt/bitnami/apps/django/conf/django.conf"
# Include conf/bitnami/passenger.conf
Include "/opt/bitnami/apache2/conf/bitnami/httpd.conf"
RewriteEngine on
RewriteMap grp prg:/opt/bitnami/apache2/conf/k.php
RewriteCond %{REQUEST_URI} ^/league
RewriteRule ^/(.*) ${grp:$1} [L]
#RewriteMap leagues txt:/opt/bitnami/apache2/conf/leagues.txt

phranque

4:57 am on Jan 1, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, nitinp!


it is not working

it don't working help me to work it please

in order to help we'll need to know what response or result you got.

have you checked your web server error and access logs for clues?

if your mod_rewrite directives are working properly and internally rewriting to your php script, then you have a php problem and should post your problem in the PHP Server Side Scripting forum on WebmasterWorld:
http://www.webmasterworld.com/php/ [webmasterworld.com]

lammert

8:42 am on Jan 7, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi nitinp, welcome to WebmasterWorld!

Is there any progress with your site, or do you still face the same problem. A description of what happens an where it fails together with some error messages from the Apache logfiles may be enough for us to help you in the right direction.