.htaccess not working and confusion - php

I've looked at numerous questions regarding .htaccess not working.
Tried them all but it still won't work for mine.
It was still working for me before, the problem started when i deleted the .htaccess file inside the application folder.
The tutorial i was following didn't specifically mention to delete that htaccess but just to copy it to the root. So basically, when it was still working i had 2 htaccess files, with the application folder and inside the application folder.
Right now, even if i deleted the .htaccess file inside the application leaving only 1 .htaccess in my project root, it still won't work.
I still have to include 'index.php' for the url to work.
It won't necessarily show me 404 when i don't include the index.php.
It just shows me this page,
This is the content of my .htaccess file.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My config file.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Apart from that, i already tried, refreshing my wamp connection, shutting down my pc then turning it on again.
I don't know whats wrong since it worked for me the first time around even if i have 2 htaccess it still won't. Something happened when i accidentally deleted that 1 file.
My system is windows 7 32-bit, and i'm using WAMP. I already turned on rewrite module for apache on my wamp. I'm using the latest codeigniter, 3.1.2
This may also give a hint,
When i load my view, the css url won't work.
The css url shouldv been localhost/project/css/bootstrap.min.css
however, same result, same page it shows above.
I also have this on my httpd.conf on my apache.
<Directory />
AllowOverride none
Require all denied
</Directory>

I'm not sure why this works but i've found an htaccess that was specifically mentioned for a ci3 htaccess problem.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
not much difference, just that it removed the '/' before the index.php and replaced the '/' to '?' after the index.php
Is this because i am using CI 3?
Codeigniter 3 remove index.php problems

Related

I have problem in .htaccess in my localhost not redirecting correctly

My .htaccess file contains:
Options +FollowSymlinks
RewriteEngine On
RewriteRule projects$ projects.php
RewriteRule projects/$ projects.php
RewriteRule projects/page/([^/]*)$ projects.php?page=$1
RewriteRule projects/page/([^/]*)/$ projects.php?page=$1
RewriteRule projects/company/([^/]*)/$ projects.php?companyid=$1
RewriteRule projects/company/([^/]*)$ projects.php?companyid=$1
RewriteRule projects/([^/]*)$ projects.php?id=$1 [L]
It was working fine, but suddenly this section is not working in my website.
This should redirect to "projects.php?companyid=$firstvariable",
but actually, I don't know why.
I tried restarting my PC and deleting temp and restarting WAMP.
After some interactive troubleshooting with OP, it appears that WAMP's Apache/PHP will execute a PHP file that matches the directory portion of the URL path if it exists, before applying the .htaccess RewriteRules.
In other words, if you have a file named Abc.php, and you request /Abc/def, WAMP's Apache/PHP will just execute Abc.php and not consult the .htaccess file.
I'm not sure if this is something special about WAMP and whether it's out-of-the-box behavior. I can't find any documentation on being able to control/change this behavior.

.htaccess rewrite on $page

It seems I am stuck. I have found answers, but I can't get them to work.
I am working on this website. I use a switch to determine what content should be visible. I use the variable $page.
The links with this method are not good for SEO so I want them to be /example instead of index.php?page=example.
I have looked at all the different answers to this on StackOverflow, but I can't get any solutions to work. There are no errors coming up and the site will show just fine, but the rewrite doesn't work.
I have tried on both my servers on servage.net and one.com
Any suggestions? :D would be much appreciated!
Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs), then point your browser to example.com/somepage:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/?$ page=$1 [L,R]
Once you are satisfied that the redirect works, you can change the R to R=301 to make it permanent.
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

Trying to figure out htaccess issues

I'm having some issues figuring out how to use an htaccess file. I've got apache/php installed on an ubuntu system and mod_rewrite is turned on (php_info() states that it's in the list of loaded modules). The web server works, displays html and php files, so I'm happy with that.
What I'm trying to figure out now is how to use an htaccess file properly. I created a directory, /data, with an index.php file in it. All I want it to do at the moment is just display the $_REQUEST variable so I can see if things are working the way I assume they should.
Example: If I type in the following URL: localhost/data/info1/ I want the htaccess file to access localhost/data/index.php?request=info1
However, no matter what I enter in to the htaccess file, I keep getting 404 errors, and I'd like to understand why.
Here's my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule data/(.*)$ data/index.php?request=$1 [L]
</IfModule>
I've made no changes to the config file, to activate mod_rewrite, I used the ubuntu a2enmod command so ubuntu did it for me. After that, I restarted apache.
What I can't figure out is why this doesn't work. My assumption is that there's still some sort of configuration I need to do on the server end, but I honestly don't know what. Is there any advice anyone can offer me?
Here's the fix:
RewriteRule ^data/(.*)$ data/index.php?request=$1 [L]
(You were missing a ^)
EDIT:
In the OP, you have another leading / in the URL example, in this case it'd be:
RewriteRule ^data/(.*)/$ data/index.php?request=$1 [L]

Redirecting all request to the root directory somewhere else?

Alright, so I've downloaded a CMS for a server I'm setting up and I have some difficulty with the path the files are on.
I have put the CMS in a subdirectory on my server as the root directory is already being used by another CMS. However, the CMS repeatedly uses "/" in the code to link to their files. For example, an image is found using this code:
<img src="/images/banner.png" />
As you know this will not work, because the link above redirects the request to the images folder in the root of the server, not the subdirectory. The CMS also came with a ".htaccess" file, so I immediately thought that I could redirect all requests made using the "/" character to the subdirectory on the server. This is the original ".htaccess" file:
RewriteEngine On
RewriteRule ^index.php(|/)$ content/.php
RewriteRule ^error.php(|/)$ content/error.php
RewriteRule ^housekeeping(|/)$ housekeeping/index.php
RewriteRule ^(|/)$ content/$1.php
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ content/$1.php
RewriteRule ^rd/([^/]+)(|/)$ /rd.php?id=$1
RewriteRule ^quickregister/start(|/)$ /register/start.php
RewriteRule ^quickregister/step2(|/)$ /register/step2.php
RewriteRule ^quickregister/step3(|/)$ /register/complete.php
RewriteRule ^community/online(|/)$ content/online.php
RewriteRule ^community/vip(|/)$ content/vip.php
RewriteRule ^credits/goldvip(|/)$ content/goldvip.php
RewriteRule ^home/(..*)$ content/home.php?u=$1
RewriteRule ^articles/(..*)$ content/articles.php?story=$1
ErrorDocument 403 /content/error.php
ErrorDocument 404 /content/error.php
I thought that by adding
RewriteRule ^/$ /subdirectory/
the requests to "/" would be redirected, but to no avail. I have checked the apache configuration and it seems that overwriting the config using htaccess files is enabled, so if anyone is able to help me out I'd be very happy.
Thanks in advance!
EDIT:
I came real close to a solution. I inserted this code just below "RewriteEngine on":
RewriteRule ^(.*)/(.*)$ /private_servers/strebbohotel/$2
This returned the following error page when visiting the url "http://mysite.com/private_servers/strebbohotel/content/.php":
Not Found
The requested URL /private_servers/strebbohotel/.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
As you can see, it skips the "content" subdirectory for some reason. I believe it has something to do with the other lines of the .htaccess file but I can't figure out which ones. It also could be that I need a more complex regex, but I'm not particularly good with it so if someone could help me further I'd be thankful.
You have to change the .htaccess file on yout root directory - and that will mess with the other CMS. The only solution that comes to my mind is to use combination of RewriteCond's:
RewriteCond %{HTTP_REFERER} my_better_cms_url_regex
RewriteCond %{REQUEST_URI} ^/images/.*$
RewriteRule ^.*$ /subdirectory/%{REQUEST_URI}
That should do the trick. If you want to customize it, refer to this cheatsheet (or simmilar). But be aware, that .htaccess in root directory is checked against ALL requests made to your subdir cms - therefore the need for second condition.
The .htaccess file in your CMS subdirectory would have no effect on requests made against the server root directory. You would need to add an .htaccess there.
Even then though, I don't know how you would differentiate requests from the CMS (like the image request in your example) from those intended for the application in the web root.
Does your CMS not have any configuration setting that allow you to specify a path the the files other than the web root?
You want to use:
RewriteBase /another_root_dir/
in the beginning of your .htaccess file

Clean URLs don’t work after upgrade

I recently upgraded my CodeIgniter app from v1.7.2 to 2.0.2.
I use mod_rewrite to produce clean URLs without index.php e.g. example.com/controller/action. It is working on my local dev server but when I updated my production app all requests to example.com/controller/action result in displaying main page (i.e. index.php).
When I access address like that: example.com/index.php/controller/action it works.
Mod_rewrite is on as it was working fine with previous code version. With 1.7.2 I used $config['uri_protocol'] = "AUTO" but now I switched to "PATH_INFO" because auto resulted in 404.
Because it is working on dev I’m wondering if I missed any deployment step. Any ideas?
There are .htaccess rules I'm using with CI 2:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
<IfModule mod_rewrite.c>
#paths that you don't want to rewrite
RewriteCond $1 !^(index\.php|assets|session|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
I think I had some similar problem and I believe it got resolved by changing permission on my root folder to 777... but that was on XAMPP

Categories