Welcome to WebmasterWorld Guest from 54.144.48.252

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite not working - .htaccess being ignored

     
12:27 pm on Feb 8, 2012 (gmt 0)



Hi

I've tried desperately to get mod rewrite working but after hours of reading, testing and failing I'm hoping so one can help me.

I'm sure mod rewrite is being loaded as it shows up using phpinfo() and I'm 99% certain the .htaccess file is being ignore as nothing I try in there works.

From my httpd.conf

<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>


.htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/$1 [R=301,L]


When I got to the home page is show redirect to example.com but doesn't.

Any help would be massively appreciated.
10:17 pm on Feb 8, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



When I got to the home page is show redirect to example.com but doesn't.

Could you please say that again in different words? Do you mean that the address bar says one thing but the page content says something else?

Paste-in from a different thread:

Simple test to see if .htaccess is being recognized and mod_rewrite is working:

RewriteRule foobar\.html http://www.example.com/rewrittenurl.html [R=301,L]

Request foobar.html in your browser. If things are working, you will wind up on the 404 page, but your browser's address bar will say rewrittenurl.html
10:04 am on Feb 9, 2012 (gmt 0)



Sorry about that, no idea why I wrote complete nonsense. What I meant to say was:

When I go to the home page it should redirect to example.com but it doesn't.

I have tried the following:

RewriteEngine on
RewriteRule test\.html http://www.example.com/rewrittenurl.html [R=301,L]


When I go to [domain.com...] it shows Page 404 Not Found. The address bar says test.html not rewrittenurl.html.
10:09 am on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Uh-oh, that means the redirect isn't happening. (That's assuming-- whoops!-- that in place of "example.com" you used your real domain name.) So now we need to take several steps back...
11:30 am on Feb 9, 2012 (gmt 0)



I did use the real domain during my test.

What's next?

Thanks
11:50 am on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Ask your host if mod_rewrite is enabled.
12:03 pm on Feb 9, 2012 (gmt 0)



I'm running this on my own server which I have complete control over. I'm using Windows Server 2008 with Apache 2.2.15.
12:27 pm on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You've restarted Apache? Make sure the AccessFileName directive is set properly in httpd.conf. Does anything happen when you insert some nonsense into .htaccess?
12:53 pm on Feb 9, 2012 (gmt 0)



I've restarted Apache each time I've tried something new.

The AccessFileName doesn't exist in my httpd.conf but I've added at the bottom, restarted Apache but I still get exactly the same result.
12:54 pm on Feb 9, 2012 (gmt 0)



What nonsense can I add to .htaccess to test?
4:24 pm on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



fhdsjkdfg


should be enough to at least generate "internal server error".
9:55 pm on Feb 9, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Look in your error logs. If you have a polite server, it will say something like "I'm sorry, but I don't understand 'fhdsjkdfg'. It might be a directive from a module that isn't installed." (Mine does this with free-standing lines of garbage.)

Oh, and while you're at it, set the error logs to the highest detail level. Debug, usually. You want to squeeze out every last piece of information.

Also make sure you're trying it in different browsers. A simple thing like an un-emptying browser cache can lead you completely astray.
1:07 am on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Been there. Done that. And still get caught by it from time to time when busy and forget to clear it.
1:45 am on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



set the error logs to the highest detail level. Debug


Is this possible in htaccess on shared hosting?
4:43 am on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Is this possible in htaccess on shared hosting?

No, darn it, only in the config file.
[httpd.apache.org...]

But I got the impression from the first post that it's the user's own server, and he confirmed it a few posts back.
8:07 am on Feb 10, 2012 (gmt 0)



I've commented everything out of my .htaccess file and added some complete nonsense, cleared my browser cache etc, gone to the page and nothing happens, by that I mean it just shows the index.php page. It's not paying any attention to the .htaccess file.

I've also changed the error logs to debug, checked in there but nothing relevant to what I'm trying to achieve.
8:43 am on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Somewhere along the line, did you say where the htaccess is located?

Come to think of it, did you ever say why you need an htaccess at all? Since it's your own server, everything should be in the config file. Except trivial stuff like Options +Indexes. Or -Indexes depending on your default.

Which-- thinking further-- is another easy thing to try. Make an htaccess containing that one line, and shove it into some random directory that's full of images or similar. Anything that doesn't have a named index file already.
2:32 pm on Feb 10, 2012 (gmt 0)



The .htaccess file I'm trying to get working is in a news folder, I have tried editing the .htaccess in the root directory as well.

I'm trying to get the following code working for Wordpress, but chose the topic of .htaccess being ignored as this is what I think is causing the problem.

# BEGIN WordPress
#<IfModule mod_rewrite.c>
#RewriteEngine on
#Options FollowSymLinks
#RewriteBase /news/
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /news/index.php [L]
#</IfModule>


I could create a test folder and put a .htaccess in there. Would this be a good idea?
2:38 pm on Feb 10, 2012 (gmt 0)



I've created a folder called test, put .htaccess in there with the following code:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) [webmasterworld.com...] [R=301,L]


The result is:

Title: 403 Forbidden
Page: Forbidden
You don't have permission to access /test/ on this server.
2:45 pm on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member wilderness is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



WordPress!

Therein lies the problem.

There are many old threads on issues with WordPress and its installed htaccess.

Somewhere, there's even multiple threads with cleaner syntax.
2:50 pm on Feb 10, 2012 (gmt 0)



I've read plenty of those threads but when I realised no matter what I try and do with .htaccess nothing happens, sorting that out first was the best place to start.
9:24 pm on Feb 10, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Never mind the rewrite. Try putting Options +Indexes in some htaccess somewhere. Any directory that doesn't have a named Index file. Does it show you an auto-index?

Remember that for ordinary humans, the most common 403 error comes from trying to view a directory that doesn't have an index. There is nothing wrong with the user; they're just trying to do something they're not allowed to do.
3:24 pm on Feb 13, 2012 (gmt 0)



That results in the same 403 Forbidden. Would it help if I posted some more config code?
10:26 pm on Feb 13, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Way back at the beginning you had this:

From my httpd.conf

<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>

.htaccess file

Options +FollowSymLinks


See Apache [httpd.apache.org] under "Options". Change the two Options statements in the config to

Options +Indexes +FollowSymLinks

with explicit leading + each time. Any difference? Remember to switch browsers and empty the cache frequently.

There are two other things you can try for experimental purposes, but let's start with that.
8:15 am on Feb 14, 2012 (gmt 0)



Unfortunately that hasn't made any difference. I'll post some more of my httpd.conf (the bits that are relevant) so you can see what I'm working with, might help.


DocumentRoot "C:/www/webroot"

<Directory />
Options +Indexes +FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>

<Directory "C:/www/webroot">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>

#Enable .htaccess
AccessFileName .htaccess


And from httpd-vhosts.conf

<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot c:/www/webroot/example
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [R=301,L]
</VirtualHost>


I have tested the non www to www redirect and that is working. If I comment out the last 4 lines of the virtualhost then I can access http://example.com.

I hope this extra information helps.
8:32 am on Feb 14, 2012 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



<Directory "C:/www/webroot">
AllowOverride None
</Directory>


i think that needs to be "AllowOverride All" or at least "AllowOverride FileInfo"
9:15 am on Feb 14, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Ouch! Yes, that extra bit of config file makes a difference. Almost everything in apache is inherited downward. The things you say in

<Directory />

will only remain in effect if they are not overridden by something in

<Directory "C:/www/webroot">

which is a more specific directory. (Psst! Add a + to those Options too!)

So saying AllowOverride None is a bit of a problem. That's assuming C:/www/webroot is the directory your site lives in, and therefore the directory that will contain any .htaccess files. What was the line intended to do?

To muddy the waters further, Apache [httpd.apache.org] says
For security and performance reasons, do not set AllowOverride to anything other than None in your <Directory /> block. Instead, find (or create) the <Directory> block that refers to the directory where you're actually planning to place a .htaccess file.

You seem to have done the opposite.

And speaking of htaccess...

<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>

Do you even need the Satisfy All line? Is there any circumstance where you would want to look at your htaccess or htpasswd file "live" rather than digging it up in (S)FTP or equivalent? I would worry that you're just creating a potential loophole.
10:05 am on Feb 14, 2012 (gmt 0)



It's working :-)

Here's what I've got now

<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>

<Directory "C:/www/webroot">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>


The directory structure is C:/www/webroot/name. Whereby name is where the site begins, as setup in the VirtualHosts file.

Example:

Intranet
c:/www/webroot/intranet

Website 1
c:/www/webroot/website1

Website 2
c:/www/webroot/website2

I'm not sure why that line is there, I'm not an apache guru so either I copied it or it was there originally. If you wouldn't mind pointing out what's wrong with my setup I'd appreciate that.

I will admit to copy and pasting the .htaccess code. I was reading something about protection those files and that's what it gave me. There are no circumstances where I would want to look at .htaccess or .htpassword so I'll remove that line.

Thanks for all your help, I'm a happy man now..
2:05 pm on Feb 14, 2012 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



what you really should have is:
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>

<Directory "C:/www/webroot/intranet">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<Directory "C:/www/webroot/website1">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<Directory "C:/www/webroot/website2">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>


and wherever you have "AllowOverride All" you should only allow those types of directives that you require to be allowed in the respective .htaccess file.

AllowOverride Directive:
http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride
 

Featured Threads

Hot Threads This Week

Hot Threads This Month