Jump to content
Larry Ullman's Book Forums

Htaccess Issues


bc24fl
 Share

Recommended Posts

So I'm following along and can't seem to get this htaccess right.  A little help would be much appreciated.  When I remove index.php i get the 404 error.  

 

Environment:

 

Windows 7 / Zend Server Apache

 

http://localhost:8080/testapp/index.php

 

.htaccess inside the /testapp/ dir is:

 

------

 

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Don't perform redirects for files and directories that exist:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# For everything else, redirect to index.php:
RewriteRule ^(.*)$ index.php/$1
</ifModule>
------

 

main.php contains:
 
'showScriptName'=>false
 
in httpd.conf
 
AllowOverrides All 

 

 

:(

Link to comment
Share on other sites

I had a few issues with the .htaccess as well. I ended up using the below which works for me.

 

Options +FollowSymLinks
IndexIgnore */*

<ifModule mod_rewrite.c>
    # Turn on the engine:
    RewriteEngine on
    
    # Don't perform redirects for files and directories that exist:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # For everything else, redirect to index.php:
    RewriteRule ^.*$ /index.php [L]
</ifModule>

Link to comment
Share on other sites

  • 8 months later...
I know that this is an old thread but wanted to share that I had the same problem with the OP. matthuisman's suggestion didn't work on my setup on Ubuntu13.10 with apache2.4.6. Instead, I had to add the following to my /etc/apache2/sites-available/mysite.conf
<Directory /var/www/mysite/>
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Then reload apache with

sudo service apache2 restart

Hope this helps someone.

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

This was a huge help. Here are a few more things to check, I'm running Ubuntu/Mint 15 on a virtualBox instance.

 

I could not get the simple examples working, .htaccess and the code was as the book has but no-go.

 

Looked at the apache2 enabled modules in /etc/apache2/mods-enabled and saw that their was a symlink set up to rewrite.load so the module was setup for loading.

 

Then took a look at

 

/etc/apache2/sites-enabled directory, it has one entry in my case which is a symlink to the /etc/apache2/sites-available/default file where I found pretty much what Gio said,

 

 <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride none
                Order allow,deny
                allow from all
 </Directory>
 

 I just changed the

 

AllowOverride none 

 

to

 

AllowOverride all

 

and restarted apache2 as Gio did below.

 

Lastly Don't forget to add the

 

'showScriptName'=>false,

 

Line to the

'urlManager' section in config/main.php file as the book shows, it's easy to miss.

 

 

And Thank You GIO!

 

Sandy

 

 

I know that this is an old thread but wanted to share that I had the same problem with the OP. matthuisman's suggestion didn't work on my setup on Ubuntu13.10 with apache2.4.6. Instead, I had to add the following to my /etc/apache2/sites-available/mysite.conf

<Directory /var/www/mysite/>
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Then reload apache with

sudo service apache2 restart

Hope this helps someone.

 

Link to comment
Share on other sites

One more .htaccess post - Moving your Yii app out of web root

 

Just got the rest of my .htaccess working for the Yii app I have been working on. The Yii app is in a subdir under the web root.

 

This seems to work well and is similar to some of the above examples, posting as it's always madding dealing with .htaccess and making things work ... This was cobbled from some other .htaccess files I had found.

 

Put this in your webroot's .htaccess not in the local Yii App directory

 

replace subdir with the directory that your yii app is in (with index.php)

replace yourdomain with the domain name of the site (may be other ways to do this without explicitly setting this)

 

As always use .htaccess on a test instance before crashing your web server...

 

============ .htaccess at web root  ============

 

# allow no one to read .htaccess

<Files .htaccess>
order allow,deny
deny from all
</Files>

# Common options, hide directory listing, etc
Options ALL -Indexes +SymLinksIfOwnerMatch

# Allow first html then php index files to be the default
DirectoryIndex index.html index.php

# Must have this!
RewriteEngine on

 

# May be the default, but doesn't hurt
RewriteBase /

# Don't apply rules to URLs that are existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Only apply to URLs that aren't already under /subdir
RewriteCond %{REQUEST_URI} !^/subdir/

# Rewrite all those to insert /subdir.
RewriteRule ^(.*)$ /subdir/$1

# Redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?yourdomain.com$
RewriteRule ^(/)?$ subdir/ [L]
 

Link to comment
Share on other sites

 Share

×
×
  • Create New...