1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess not working

Discussion in 'PHP' started by bhuppi890109, Jun 29, 2011.

  1. #1
    hi all..i am creating a new website and using a .htaccess file which convert web address in the form of querystring..and it works properly in my institute..but not working at home ..is there any special thing to do to use .htaccess file..here is the data of .htaccess.......



    this file should store first address after index.php in to section variable as query string and next one into action variable and so on

    for e.g. www.example.com/ex1/ex2

    above address should word as www.example.com/index.php?section=ex1&action=ex2

    but when i am putting the address then it shows the error "The requested URL www.example.com/ex1/ex2 was not found on this server.
     
    bhuppi890109, Jun 29, 2011 IP
  2. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do the other rules work, other than that huge one? If not, you probably don't have mod_rewrite installed/configured properly on your apache server. Or, you might, but you don't have your site files picking up .htaccess correctly.
     
    ntomsheck, Jun 29, 2011 IP
  3. balaganesh

    balaganesh Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    htaccess file you can check it in google
     
    balaganesh, Jun 29, 2011 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    Bloody hell. When you say it works at your institute, but not at home, do you mean you have two installations of the website set up? That's all serverside, so if you're accessing the one resource from two different locations it should work.

    If you have two installations, try checking your Apache configuration. if you don't have root access to the server, the easiest way is probably to create a simple phpinfo() file and look to see if the mod_rewrite module has been loaded. Personally, I wouldn't create a rule like that. It would be easier to rewrite everything to index.php, and have the PHP script retrieve and format the variables. For instance, on a block of code I just wrote:

    .htaccess
    <IfModule mod_rewrite.c>
    	RewriteEngine On
    	
    	RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteCond %{REQUEST_FILENAME} !-d
    	
    	RewriteRule ^(.*)$ dispatcher.php?url=$1 [PT,L]
    </IfModule>
    Code (markup):
    Block of code in dispatcher.php that retrieves the variables from the URL:
    function dispatchRequest( $passThrough ) {
    	$urlParts = explode( '/', $_GET['url'] );
    	
    	// Try to fetch the controller/action/vars from the URL query.
    	try {
    		$controller = trim( $urlParts[0] );
    		$action = $urlParts[1];
    		
    		$vars = array();
    		if( isset( $urlParts[2] ) ) {
    			for( $x = 2; $x <= sizeOf( $urlParts ) - 1; $x += 2 ) {
    				$vars[ $urlParts[ $x ] ] = $urlParts[ $x + 1 ];
    			}
    		}
    		
    	// Otherwise, let's just load up the default values
    	} catch( Exception $e ) {
    		if( ! isset( $controller ) ) $controller = 'index';
    		if( ! isset( $action ) ) $action = 'index';
    		if( ! isset( $vars ) ) 	$vars = array();
    	}
    Code (markup):
    Cut the function off and a bit of it is redundant for your purposes. However from the url http://localhost/pages/view/id/1/action/edit the vars array would be:
    [id] => 1
    [action] => edit
    Code (markup):
    Technique like this is probably more beneficial and flexible.
     
    Alex Roxon, Jun 30, 2011 IP