Platform: Windows 7 Pro 64 bit
I have Apache 2.2 setup on my development machine (basically a WAMP setup). I have several installs of Code Igniter based websites in the main htdocs. However, I am getting stuck on handling case for sub directories under the main htdocs directory.
Here is where I am having issues with .htaccess (located in the /CILearn directory under htdocs):
RewriteEngine on
RewriteBase /CILearn/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /CILearn/index.php/$1 [NC,L]
The sub directory is CILearn under htdocs. So the URL looks like this:
localhost/CILearn
localhost/CILearn/site
localhost/cilearn
Now this works and "site" is a controller so the redirect for index.php is working.
This does not work:
localhost/cilearn/site
Can someone please explain where these rules should and why it is not handling case?
remove
RewriteBase /CILearn/
and test it again , see this page http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase for more information about RewriteBase
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /CILearn/index.php/$1 [NC,L]
This can happen, when your file system paths are case sensitive. You have two options here.
Use mod_speling in the root dir .htaccess (not /CILearn/.htaccess)
CheckSpelling on
CheckCaseOnly on
Be sure mod_speling is activated with something like
LoadModule speling_module /path/to/apache2/modules/mod_speling.dll
Alternatively, you can add a RewriteRule fixing the case for cilearn. This must be done in the root dir .htaccess
RewriteEngine on
RewriteRule ^cilearn/(.*) /CILearn/$1 [NC,L]
Related
I've wanted to move my index.php file from the root to /system/ folder, this is for no reason but giving myself opporunity to learn more about .htaccess, which I am finding very confusing.
How can I achieve this? Currently my code looks as follows
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?query=$1
This allows for example mydomain.com/some-url/ to become /index.php?query=some-url for example, this far I'm with it all. But moving the file into System folder and addind /system/ before /index.php does nothing. How does one do this? Thanks!
This could be done with a simple rewriterule. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*)$ system/index.php [L]
I'm working on a project hosted on the Cloud9 IDE. I had a simple set of mod_rewrite rules set up, but they no longer work after c9's new version rollout. It took me forever to iron out these rules (I'm a novice at best at this) I'm confused as to why these rules no longer work (AFAIK, the new c9 version should not have affected mod_rewrite rules).
Here are the rules (located in the root .htaccess)
RewriteEngine on
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_URI} ^/css/.*$ [OR]
RewriteCond %{REQUEST_URI} ^/img/.*$ [OR]
RewriteCond %{REQUEST_URI} ^/js/.*$
RewriteCond Astralis/resources%{REQUEST_URI} -f
RewriteRule ^(.+)$ Astralis/resources/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
The goal is pretty straightforward... All requests going to /css/... /img/... or /js/... should serve up the associated file within Astralis/resources (after checking that the file exists). Otherwise, redirect the rest of the traffic to index.php.
The problem I am experiencing is that all requests to resources (css, img, js) are returning 404's. If I move the /css, /img, and /js folders from within Astralis/resources back to the root directory, all the resources load properly. This problem started happening after c9's new version, with no changes to the .htaccess file, the codebase, or directory structure.
Any clue as to what is going on? How do I debug this kind of stuff? Any general tips/tricks for writing mod_rewrite rules would also be appreciated. Thanks.
Since Apache needs full path of the file in order to return true using -f you will need to use %{DOCUMENT_ROOT}/ before your file path.
Have it this way:
RewriteEngine on
Options FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(css|img|js)/ [NC]
RewriteCond %{DOCUMENT_ROOT}/Astralis/resources%{REQUEST_URI} -f
RewriteRule ^(.+)$ Astralis/resources/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
i'm trying to remove index.php form an URL:
this works
http://server/bw/index.php/test
this doesn't work
http://server/bw/test
i try to change .htaccess and watching on web i see that it should be like this:
RewriteEngine On
RewriteBase /bw/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
i try editing it in this way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
or in this way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /bw/index.php [QSA,L]
or in this way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
But when i try to access to http://server/bw/test it says me:
Not Found
The requested URL /bw/test was not found on this server.
Apache/2.2.15 (CentOS) Server at server Port 80
I check that inside my httpd.conf LoadModule rewrite_module modules/mod_rewrite.so is enable.. i don't know what to do now..
how can i solve? please help me!
Try this, which used e.g. in WordPress
RewriteRule . index.php [L]
or this, which is used by e.g. Lavavel PHP Framework
RewriteRule ^(.*)$ index.php/$1 [L]
You might also consider adding
RewriteCond %{REQUEST_FILENAME} !-d
before the RewriteRule to also exclude existing directories, not only existing files. But that's up to you.
In my case I updated AllowOverride All ,
then run sudo a2enmod rewrite to avoid Internal 500 error then restart Apache service apache2 restart
For me, I got things to work using this line from Dehalion's answer:
RewriteRule . index.php [L]
So the index.php (or any xyz.php) file is not seen in the request url
http://localhost/demo1/mycompany/hello/Jim
With the following caveats:
You have this route defined:
$app->get('/mycompany/hello/:name', doHello );
The root element (for the route /mycompany/..) is also the name of the file.
That is, the route exists in a file called "mycompany.php"
Yes, it's a bit of a hack ... but since I find apache config confusing/intimidating :) ... I figure this solution is stable enough to satisfy the requirements.
Having some issues with .htaccess on my website. I'm trying to alter the suffix of the URLs for my website. URLs currently appear as:
www.example.com/about.phtml
I want to remove about.phtml and replace it with about so it looks like:
www.example.com/about
The examples I'm using are not what I need on the website so I would like code that I don't have to go through and specify which specific page to remove it from and rather do it all automatically.
I've tried using php instead of phtml with no luck. Here is the code I am using:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml
Any ideas what I am doing wrong here?
FYI: my host is JustHost and they allow me to edit my .htaccess but if anyone has heard of or had any problems with them please let me know, I spoke to their tech-support who couldn't help me any more than I can help myself.
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.phtml [NC,L]
This works for me:
RewriteEngine on
RewriteRule ^/?([a-z]+)$ $1.phtml [L]
You can Check first your rewrite mode is on or not in apache\conf\httpd.conf file
check below code in httpd.conf file
#LoadModule rewrite_module modules/mod_rewrite.so
if hash exist in above the line then remove hash and restart apache server
After then you can set below code in your cakephp httaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.phtml -f
RewriteRule ^(.*)$ $1.phtml [NC,L]
</IfModule>
I have this htaccess setup on my clients site, they use godaddy
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
it worked fine on my MAMP but does not seem to work on the server
they have setup a subdomain like demo.example.com and the htaccess exists in the demo folder but I get 404 trying to get to page like demo.example.com/test but demo.example.com/test.php works fine so this tells me the htaccess is not work. does anyone know what I need to do to make this work ?
Try:
1) Add this line into your .htaccess: Options +FollowSymlinks
2) Add leading slash before $1, e.g. RewriteRule ^(.*)$ /$1.php [L,QSA]
P.S. There are some "rumours" that GoDaddy may not pick up changes in .htaccess file straight away.
I would also suggest to define custom 404 error handler (simple PHP script) that may help with debugging this (put this line into your .htaccess):
ErrorDocument 404 /404.php
404.php (as simple as this)
<?php
Echo "404\n";
phpinfo(INFO_VARIABLES);
The details there may help identify the issue.
UPDATE:
We have a domain name & hosting that we do not use which is about to expire. So I have logged in and tested these rules myself. Got it working straight away. Here is the setup I have:
Apache/1.3.33
Hosting Configuration: 2.1
PHP 5.x (did not bothered to check exact version)
Data Center: US Regional
.htaccess was already present and had only 1 line 9possibly left over from the site that was there originally):
addhandler x-httpd-php5 .phtml
These lines were added to .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]
I have created simple php file to check if it works. Called it echo.php. Then I have tried these URLs:
http://www.example.com/abcd -- saw error page (as expected)
http://www.example.com/echo -- saw my page -- echo.php (as expected)
The full physical path to the echo.php is: /home/content/b/u/y/buyxxxxxxx/html/echo.php; ftp/website root is /home/content/b/u/y/buyxxxxxxx/html/
Try this simple setup. DO not do anything complex until you solve this issue.
This is right way of play with .htaccess on godaddy
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L,QSA]
This answer on Stack Overflow might help you aswell:
Add this:
Options +FollowSymLinks -MultiViews -Indexes
at the very top and give it a try.