How to remove index.php from slim framework URL - .htaccess

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.

Related

Point to a file in subfolder with .htaccess

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]

Remove subfolder with htaccess

This is the architecture of my website :
/
app/
index.php
...
libs/
lib1/
file.php
lib2/
...
I need to access index.php by this url : domain.com/index.php
I tried this :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)app
RewriteRule ^(.*)$ app/$1 [L]
It works, but inside my index.php, I call for example :
include('../libs/lib1/file.php');
It's doesn't work because this path refer to root now...
And I can't access to domain.com/libs anymore, because it's looking for domain.com/app/libs.
How can I do ?
The include() shouldn't care what the path the browser sees. That should be based on the local filesystem on the server. But your rules are affecting direct access to the libs, so try adding a few more conditions:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^app/
RewriteRule ^(.+)$ app/$1 [L]
RewriteRule ^$ app/index.php [L]
This makes it so requests for existing files or content won't get routed through the app folder.

htaccess RewriteRule not handling case

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]

Mod rewrite not working at all (phtml/php)

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>

Error installing Social Engine

I've got a problem trying to install Social Engine. Upload all files, set directory permissions, but when I enter my domain, I get a:
Not Found
The requested URL /install/install was not found on this server.
It's something related to the .htaccess files in root and install directory, 'cause removing them I do begin the installation process BUT with long URLs, this way:
/install/index.php/install
And that's something that would end up with all long URLS, instead of short ones that google use to index, for example. My ISP has safe_mode OFF, and mod_rewrite ON, so I'm just kinda lost...
.htaccess :
# $Id: .htaccess 7539 2010-10-04 04:41:38Z john $
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
Had the same issue running SocialEngine on Vagrant (using https://box.scotch.io/) and fixed it by clearing the .htaccess file under /install/.

Resources