-
Apr 1st, 2024, 10:56 PM
#1
Thread Starter
Fanatic Member
[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]
-
Apr 2nd, 2024, 08:58 AM
#2
Re: Problem loading images, scripts and styles after coding in htaccess file
Originally Posted by Black_Storm
... 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.
Originally Posted by Black_Storm
... 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 + javascript + 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]
-
Apr 3rd, 2024, 09:20 AM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|