I'm pretty new to Codeigniter and have done all possible searches that I can do before reaching here.
I am using Code igniter 3x, my local CSS, Images and JS are not getting loaded into the Codeingiter application. I tried directly opening the CSS path but i believe Codeingiter assumes the path to be class/method/parameters! Below screenshot for reference.
[
Following is my .htaccess file:
DirectoryIndex
RewriteEngine on
RewriteCond $1 !^(index\.php|img|assets|css|js|robots\.txt|favicon\.ico|logo\.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./$1 [L,QSA]
Any help on this would be highly appreciated.
Anything that needs to be changed?
As suggested by #Bhavesh Parab over comment, pleacing the asset folder at root fixed the issue.
Related
i have one domain and one server for all my web app, my server already got a wordpress and a php app but i want to add a symfony app on it (i really understand that's not a good way to do it).
But i have troubles with my .htaccess...
My server looks like :
server_root
My wordpress works correctly, myapp1 (full php) works correctly, but myapp2 (Symfony 4) doesn't seems to work.
When i go to www.mydomain.com/myapp2/public i have the good redirection to www.mydomain.com/myapp2/public/login but with a wordpress 404 not found error ...
i'm 100% sure i have to change something in the .htaccess file but i can't figure out how making it work...
i tried to add some lines but nothing seems to work..
here is the .htaccess file of my server :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
i really need help on this ... sorry to bother with my problems,
thanks in advance
As Jenne said your current .htaccess for your Wordpress application does rewrite everything which is not
an existing directory
an existing file
to the index.php of Wordpress.
That is why your PHP application has worked fine. Symfony however needs a rewrite of everyting to its index.php too.
I do not recommend locating Symfony inside a public directory. As Jenne said you should locate it outside of it and e.g. create a own subdomain which root directory is the public directory of your Symfony application.
But you can add an extra rewrite rule to your .htaccess file which does the needed rewriting for Symfony.
# If the path points inside the myapp2 public folder
RewriteCond %{REQUEST_URI} ^/myapp2/public/.
# and there is a file at that path
RewriteCond %{REQUEST_FILENAME} -f
# use that file.
RewriteRule ^ - [L]
# If the url points to /myapp2 use the Symfony index.php.
RewriteRule ^/myapp2(/.*)?$ /myapp2/public/index.php [L]
# If the path points to something which is no existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# use the Wordpress index.php.
RewriteRule . /index.php [L]
That way you can access all files in the Symfony public directory like that:
www.example.com/myapp2/public/somefile.txt
And use everything else at /myapp2 for your Symfony routes. But all files which are in your myapp2 folder and outside of the public folder can't be accessed.
Lets do a warning first: having all these files in those public folders like this is very BAD as we can simply open the configuration files browsing to eg yourhost/myapp1/config/services.yaml. And these will be fully readable! It is therefor advised to only expose the public folder of symfony projects (the one that has the index.php) to the outside world. Or you would have to edit the htaccess even further to only allow acces to specific file types/folders like assets
There is an answer to the question though, what is going on is:
# If the requested path is NOT (!) an actual file (-f) on the disk
RewriteCond %{REQUEST_FILENAME} !-f
# And if the requested path is NOT (!) an actual directory (-d) on the disk
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite any path (`.` is a regex where the dot will match anything) to /index.php
RewriteRule . /index.php [L]
There for calling file/directory in myapp1/2 would work as they are actual file calls and wont get forwarded to the root/index.php (wordpress).
We can solve this by adding
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/myapp1
RewriteCond %{REQUEST_URI} !^/myapp2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
The first two can also combined in regex using RewriteCond %{REQUEST_URI} !^/(myapp1|myapp2)
This results in any path:
NOT starting with /myapp1
AND NOT starting with /myapp2
AND IS NOT a file
AND IS NOT a directory
being rewritten to /index.php.
You can then also add a .htaccess in myapp1/2 to do the rewriting for those apps specifically.
There are a lot of info about this here at Stackoverflow, but nothing seems to work for me! I have rewritten some URL in the .htaccess file and it's working, but then I discovered that the CSS and images was lost. And I read and read about how to change path from relative to absolute, but I'm not shore this helps or perhaps I'm doing this the wrong way!?
.htaccess file:
RewriteRule ^bilder-byggnader-kopenhamn$ /?p=byggnader [L]
RewriteRule ^bilder$ /?p=byggnader [L]
RewriteRule ^byggnad/(.+)$ /?p=byggnad&id=$1 [L]
It's only the third row in the .htaccess file that cause this problem. First and second row don't affect the CSS and images.
From the beginning my CSS file was just like this styelsheet.css since it's located in the root. I then changed it to http://127.0.0.1/stylesheet.css, but it still doesn't work. I haven't yet done this with the images, but I guess I should be the same there like http://127.0.0.1/images/image.jpg.
You should consider adding:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
so rewrite rule won't work for existing files and directories (for example for images and stylesheets)
First modify your rules like this:
RewriteEngine On
RewriteRule ^bilder-byggnader-kopenhamn$ /?p=byggnader [L,QSA]
RewriteRule ^bilder$ /?p=byggnader [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^byggnad/(.+)$ /?p=byggnad&id=$1 [L,QSA]
Then make sure to use absolute path in your css, js, images files rather than a relative one. Which means you have to make sure path of these files start either with http:// or a slash /.
I'm trying to load images from a staging site if they don't exist locally.
This is basically useful so I don't have to keep downloading all the images that the client uploads on the staging site. At the moment, what I have is working, but it's an all-or-nothing solution. So, all the images are loading remotely but I'd like htaccess to only load remote images if a local one doesn't exist.
Here's what I have:
RewriteCond %{HTTP_HOST} ^local-site\.dev$
RewriteRule ^.*/uploads/(.*)$ http://remote-site.com/wp-content/uploads/$1 [L,R=301]
Thanks in advance.
Change your rule to this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^local-site\.dev$
RewriteRule ^.*/(uploads/.*)$ http://remote-site.com/wp-content/$1 [L,R=301,NC]
Here RewriteCond %{REQUEST_FILENAME} !-f will make sure that this redirection happens only when image file doesn't exist locally.
what have you done since Wordpress v3.0, all direct PHP files are not working in WP, all are returning 404 page not found, I have created one plugin, it's loading /wp-content/plugins/myplugin/direct.php file and what am I seeing now, it shows me my WP site with title PAGE NOT FOUND 404, help me please I can't work with WP any more, all direct PHP files are not accessible and tracked as 404.
What should I do to turn off that terrible 404 or get my php files loaded.
Check your .htaccess file, maybe all URLs now are mapped to the index.php file of Wordpress.
Based on the provided rewrite rules, I would suggest to use this instead:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm not understanding the question. You're saying that you've created a plugin, and it's not calling in the files properly? (I'm assuming by "direct PHP file access" you mean you can't load a particular file that's within your plugin directory?)
Sounds like you're not using the correct paths. You should be using things like WP_PLUGIN_URL constants that are set up for you via WordPress (http://codex.wordpress.org/Determining_Plugin_and_Content_Directories) - i.e it doesn't sound like an .htaccess issue, it sounds like improper coding in the plugin.
Of course, without knowing what code you are using, it's difficult to say what the issue could be.
I'm using Wordpress and have the following pemalink /%category%/%postname%.
This gives me user friendly URLs like http://www.example.com/something/.
With this permalink, I will not be able to access php files directly, e.g. http://www.example.com/something/myfile.php.
I need to write a ReWrite rule which allows me access to /include/myfile.php.
Can some help me please? :)
Here's my current .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myblogdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myblogdirectory/index.php [L]
</IfModule>
# END WordPress
Update
Ok, I got it working.
I was doing it wrong from the start. I was using the "virtual" path instead of the physical path.
Instead of /mysite/includes/myfile.php, I have to use /wp-content/themes/mytheme/include/myfile.php
I could probably also have added RewriteCond %{REQUEST_URI} !myfile.php, which would have excluded myfile.php from the rewrite rules. I have not tested this though.
Well, your rewrite rules looks good.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
means that /blog/index.php won't be serverd if %{REQUEST_FILENAME] is a physical file or directory.
More info here.
Are you sure that you're using the correct file paths?
The file you want to request should be located in /blog/include/myfile.php.
Check your error.log for apache for any related messages.