Results 1 to 3 of 3

Thread: [RESOLVED] Problem loading images, scripts and styles after coding in htaccess file

  1. #1

    Thread Starter
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    579

    Resolved [RESOLVED] Problem loading images, scripts and styles after coding in htaccess file

    I have addresses like the ones below that are all related to one product :


    http://a.net/skins/them-black/p214-l...titlehere.html
    http://a.net/skins/them-black/p214-l...elongtitlehere
    http://a.net/longtitleherelongtitleh...titlehere.html
    http://a.net/skins/them-black/p214
    http://a.net/them-black/p214
    http://a.net/them-black
    http://a.net/p214
    http://a.net/skins


    I wanted to write a code to process all of them, I used the following method in htaccess file :


    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)$ index.php?keys=$1 [NC,QSA]


    in index.php i used this line in header too :


    <base href="/">


    and some commands for check parameters like as :


    $params = explode( "/", $_GET['keys'] );


    but still my images, styles and script files are not loaded , the reason is clear because it seems that all the requests go to the index.php , how can I solve this problem while I have also used the base commands in header and htaccess.


    If I need to write a better code, what code can cover that example without causing problems in loading the resources files (css,images,js files)?
    [ ... active on skype and discord ... ] ,[always strive to achieve your dreams] , [always try,dont stop,never say never]

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,809

    Re: Problem loading images, scripts and styles after coding in htaccess file

    Quote Originally Posted by Black_Storm View Post
    ... the reason is clear because it seems that all the requests go to the index.php ...
    Correct. Right now you're turning all requests to index.php with the original request as a query string.

    Quote Originally Posted by Black_Storm View Post
    ... how can I solve this problem while I have also used the base commands in header and htaccess.
    I would setup a RewriteCond so that it excludes your resources files. For example, assuming your file structure looks something like this:
    + /
    + images
    -image1.png
    -image2.png
    + javascript
    -script1.js
    -script2.js
    + css
    -style1.css
    -style2.css


    Then you could add the following to your htaccess:
    Code:
    RewriteEngine on
    RewriteBase /
    
    # exclude requests to the resource directories
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteCond %{REQUEST_URI} !^/javascript/
    RewriteCond %{REQUEST_URI} !^/css/
    
    # redirect all other requests to index.php
    RewriteRule ^(.*)$ index.php?keys=$1 [NC,QSA]
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Fanatic Member Black_Storm's Avatar
    Join Date
    Sep 2007
    Location
    any where
    Posts
    579

    Re: Problem loading images, scripts and styles after coding in htaccess file

    thanks for help,i resolved my problem base on this codes :

    htaccess :
    Code:
    RewriteEngine on
    RewriteBase /
    
    <IfModule mod_rewrite.c>
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>


    php :
    Code:
    
    $url=urldecode(ltrim($_SERVER['REQUEST_URI'],'/'));
    $param = explode( "/", $url);
    .
    .
    .


    [ ... active on skype and discord ... ] ,[always strive to achieve your dreams] , [always try,dont stop,never say never]

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width