www.webdeveloper.com
Results 1 to 5 of 5

Thread: .htaccess (I can't do it)

  1. #1
    Join Date
    Mar 2008
    Posts
    55

    .htaccess (I can't do it)

    Can you help me write my .htaccess please.

    I have the following:

    Code:
    AddType x-mapp-php5 .php
    
    RewriteEngine on
    
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteRule .php$ /404.php
    
    RewriteRule /english/ /index.php?l=en-gb
    RewriteRule /français/ /index.php?l=de
    RewriteRule /deutsch/ /index.php?l=de
    
    ErrorDocument 404 /404.php
    The first line makes it parse .php files as php5 instead of php4 (the server has both and defaults to php4). That works.

    The first rewrite rule and condition is to make non-existent PHP pages show a 404 page instead of "No input file selected.". That works.

    The last line is to get a custom 404 page for any wrongly typed page, instead of the server's default 404 page. That works.

    The middle rewrite rules do not work. I basically want to change a link with only directory path into a link to my index page with a query string.

    I am not sure of the format or the order things should appear in, or even if the lines are right.

    Can someone tell me how it should look?

  2. #2
    Join Date
    Mar 2008
    Posts
    55
    Got it working like this:

    Code:
    AddType x-mapp-php5 .php
    
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^english/$ /index.php?l=en-gb
    RewriteRule ^franšais/$ /index.php?l=de
    RewriteRule ^deutsch/$ /index.php?l=de
    
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteRule .php$ /404.php
    
    ErrorDocument 404 /404.php
    But all the images and links are broken.

  3. #3
    Join Date
    Sep 2008
    Posts
    408
    Guessing base directories?

    Code:
    RewriteRule ^english$ index.php?l=en-db [L]
    ^ for the beginning, $ for the end, you don't need the first /.

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    This is where your <base> tag comes in handy.

    Put that in your document head and make all links and images relevant to the base url declared in the base tag....that's how I always get around URL rewrites breaking my images (among other things).

  5. #5
    Join Date
    Mar 2008
    Posts
    55
    What about
    Code:
    RewriteRule ^english/([a-z]+\.php)?$ /$1?l=en-gb
    so e.g. /english/example.php will become /example.php?l=en-gb

    edit: when do I need the [L] ? And I don't need base? It works without.
    Last edited by Carth; 07-07-2009 at 02:13 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles