.htaccess pointing css, images and js to public folder bug - php

I currently moved my custom build cms to another environment and now my rewrite doesn't work anymore and i can't figure it out. Can someone give me any hints? The things that have been changed is going from ubuntu to CentOs and from PHP 5.5 to php 5.3. My htacces looks like this:
RewriteEngine On
RewriteBase /
#point css, images en js folders to Public folder
RewriteRule ^img/(.+)?$ Public/img/$1 [NC,L]
RewriteRule ^images/(.+)?$ Public/images/$1 [NC,L]
RewriteRule ^style/(.+)?$ Public/style/$1 [NC,L]
RewriteRule ^js/(.+)?$ Public/js/$1 [NC,L]
RewriteRule ^fonts/(.+)?$ Public/fonts/$1 [NC,L]
RewriteRule ^css/(.+)?$ Public/css/$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
A friend of mine wrote this and is now on vacation. Thanks in advance
Update: mod rewrite seems to work, becouse it redirects me.
The problem seems to appear only on images, it works for my css and js, i don't think the problem is .htaccess related anymore

Is mod_rewrite even active on your new system or does the error occur with this single .htaccess file only?
If you didn't set up the rewrite module you can follow this guide:
http://www.ghacks.net/2009/12/05/enable-mod_rewrite-in-a-ubuntu-server/

Related

RewriteRule to redirect to php file not working

I just want a simple redirect to clean up the url's on a site.
e.g.
I want ajhtestserver.com/registration/ to redirect to ajhtestserver.com/registration.php
It should be easy and I have successfully used .htaccess rewrites on other sites but for some reason it just will not work for me today.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^registration[/]$ registration.php [NC,L] # Handle requests for "registration"
I am sure it is something simple that I am missing but I basically just copied what I have on other sites that work fine for me so I am confused as to why it just refuses to work for me here (gives me The requested URL /ajhtestserver/registration/ was not found on this server. error). Just one of those days :(
Any help is appreciated.
Thanks,
Adam
if you use apache ,first you should enable rewrite_mode in http.conf or ...\
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^registration/(.*)$ registration.php/$1 [L]
check .htaccess syntax or rewrite mode.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)[/]$ $1.php [L]
Well it didn't seem to like it when the redirect source word and target filename were the same word but this works...
RewriteRule ^([a-zA-Z\ ]+)[/]?$ $1.php [NC,L]
And that is actually a better solution anyway as it doesn't require a separate rule for each page.
Though I never did figure out why it didn't like it the original way.

php application made using codeigniter framework links are not working

I set up a ubuntu server in a virtual pc. and I put my php application that was created using codeigniter framework to /var/www/sdbl folder.
now i can view the index page of my application. but all links are broken.
I put these codes in to .htaccess file and it is in /var/www/sdbl folder.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
the same application is working well on this link
http://3linksit.com/sdbl/
can some one give me some help with this issue?
Thanks in advance.
If i have got your question right you want to make your links working & remove 'index.php' from URL.Follow following steps & let me know if that solves your issue.
1) Remove 'index.php' from config.php which is located in config directory
make it look like this $config['index_page'] = '';
2) Add this to .htaccess file
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
If you have any doubts or issues let me know.Hope it helps.
Best Regards,
Zeeshan.

CI not working locally

Instead of working live on my site I've decided to try and work locally and install new version later on my live site.
So I'm working with Codeigniter and have the following struture.
/htdocs/kow(site)/kowmanager(cms)
When I load https:localhost/kow it loads the correct controller however for some reason its not reconizing that kowmanager is a sub directory of kow with its own application folder and it should be loading the default controller that is set in its routes file. When I load https://localhost.com/kow/kowmanager it loads a page that says index of /kow/kowmanager and then a link to the parent directory. Which isn't anything CI related.
Inside the kow directory this is my .htaccess file. Is this the problem?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I'm using xxamp.
You need an index.php-page for each application as stated by the manual.
So I think you should copy your index.php to indexManager.php and in it change the application folder.
$application_folder = "kowmanager";
About the rewrite I am not sure but I think it is in line with:
RewriteEngine On
RewriteBase /kowmanager
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ indexManager.php?/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
are you using a .htaccess to remove index.php from urls ?
is /htdocs/kow the base directory of your project where CI is installed ?
you need to put kowmanagers in the controllers directory, and specify which controller to call, I'm not sure CI supports calling default controllers from directories unless you specify it in the routes.php config file.
Anyway, please give further information if you want a precise answer.
What is in kowmanager and why do you have two rewrites? If your directory structure is how I assume it is, you might get away with just removing the second kowmanager directive from your .htaccess file.
Which folder is codeigniter in? All you want to do is rewrite the url to remove index.php, but unless you're mapping the url to codeigniter's index.php, it will never be able to load controllers.
Apache has a lot of info on url rewrite. Its a lot of reading and the behavior is always pretty finicky, but maybe it will help you:
Otherwise, more info will help us help you. P.S. I'd also tag this with apache, as that is where the problem is, and you're more likely to get people who know a lot about apache to view your question.

Linking to file without extension (.php removed through .htaccess) not working on one page

I succeeded in making .htaccess rewrite URLs so I can link to pages without having to define the extension. But, only one of the pages won't work.
The page is called 'games.php' and I link to it through Go to Games!
But whenever I go to it, it goes to '/games/', as if it were a folder, and then gives an Error 404.
I don't know how to fix it. I checked, there's no folder or any other file called like this, and it works on all the other pages... (also on games?id=blabla...)
Here's my .htaccess code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
Thanks in advance,
Dalionzo :D
RewriteEngine On
RewriteBase /
RewriteRule ^games(.*)?$ games.php$1 [L,QSA]
RewriteRule ^games(/)?$ games.php [L,QSA]
UPDATED
Now it works without parameters too.
website.com/game.php?id=blablabla --> website.com/game?id=blablabla

removing .php extension from .htaccess (404?)

I'm trying to removing .php extension from the url using .htaccess i've found a view sites that told me how to do this and i'm using;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
However when i go to mydomain.com/user/settings (that would be mydomain.com/user/settings.php without the .htaccess)
It works fine. However when i go to mydomain.com/user/settings/ (trending splash on the end) it gives my custom 404 error page i've looked around on here (& Similar Questions) ask and google but can't really seem to work out what part i'm missing out?
Thank You,
Flexer
Try this to handle the trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]

Categories