Monday, November 9, 2009

htaccess,mod rewrite tips

if your intention to code and decode mod_rewrite urls and handle it with php and mysql ,this should work

to convert to url
$url = preg_replace('/[^A-Za-z0-9_-]+/', '-', $string);


And to check in mysql with the url value,use the same expression discounting '-'.first replace the url value  with php using preg_replace  and use with mysql REGEXP

$sql = "select * from table where fieldname_to_check REGEXP '".preg_replace("/-+/",'[^A-Za-z0-9_]+',$url)."'"

http://www.freewebmasterhelp.com/tutorials/htaccess/

Error display
php_flag display_errors on
#E_ALL ^ E_NOTICE
php_value error_reporting 2039

condtional flag settings based on php version

# PHP configuration values

< IfModule mod_php5.c >
  php_flag register_long_arrays On
  php_flag register_globals On
  php_flag display_errors Off
< /IfModule >

< IfModule mod_php4.c >
  php_value session.use_trans_sid 0
  php_value register_globals 1
  php_flag display_errors On
  php_flag track_errors Off
< /IfModule >

enabling url rewrite
RewriteEngine On
RewriteBase /

check for hostname
#RewriteCond %{HTTP_HOST} ^myhostname\.com
#RewriteRule (.*) http://www.myhostname.com/$1 [R=301,L] 


Check for Query string
RewriteCond %{QUERY_STRING} ^options\=(.*)$
RewriteRule ^(.*)-p-(.*).html$ script.php?var=$2&%{QUERY_STRING}

Rewrite  for file name
RewriteRule ^(.*)-p-(.*).html$ redirect.php?var=$2%1

Rewrite based on browser
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]



password protection
http://www.freewebmasterhelp.com/tutorials/htaccess/3

No comments:

Post a Comment