Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Completely failing to use mod_rewrite

Status
Not open for further replies.

mirshafie

Technical User
May 31, 2011
3
SE
I'm trying to use mod_rewrite for a client's site, but have got stuck with the simplest of things. It simply seems like nothing at all is happening.

In despair, I finally regressed to following a guide for dummies. Hence I created alice.html and bob.html, and populated .htaccess with the following words:


RewriteEngine on
RewriteRule ^alice.html$ bob.html


This is supposed to rewrite alice.html to bob.html. But nothing happens. Alice is alice, bob is bob.

mod_rewrite is enabled according to phpinfo. I've restarted Apache and cleared the cache. All files are owned by apache with full permissions, and accessible. I can't think of anything else to do but to kindly ask you people for advice.

Where did I go wrong?
 
Hi!

Thanks for the suggestion.

I added RewriteLog to httpd.conf, and sure enough the logfile was created at my specified location. I began at RewriteLogLevel 10 decremented to 1, each time restarting Apache and accessing different sites and pages on my server that have Rewrite enabled.

The logfile remained empty for each level. (Not that I expected anything to happen after level 10 failed, but hey, you never know.)
 
I have AllowOverride All (which I should have mentioned in my first post).
I have not tampered with AccessFileName (but I've tried specifying it to be .htaccess since you suggested it).
I have no Redirects or RedirectMatches.


I started to get really annoyed so I have been troubleshooting some more, and basically realized that the problem really isn't with the commands I give. It seems that Apache simply ignores everything that I tell it to do in the files under sites-available and .htaccess.

To test my configuration I tried password protecting a site with .htaccess and the file in sites-available. No luck. Password protection finally worked when I added the config inside <Location> tags to httpd.conf instead. However, the same does not seem to work for the RewriteRules I mentioned earlier.

So I fear that I might have made an even more basic mistake.

To enable the sites, I have:
1. made a copy of sites-available/default
2. edited the new file, changing DocumentRoot and <Directory /path/>
3. run a2ensite MySite
4. restarted apache by the init.d script

That is basically all I have done since I installed Apache, for a couple of different sites.

I can't believe I'm asking this, but am I missing something?
 
Hi

mirshafie said:
Password protection finally worked when I added the config inside <Location> tags to httpd.conf instead. However, the same does not seem to work for the RewriteRules I mentioned earlier.
Note that [tt]RewriteRule[/tt] is getting abit different data when is placed in httpd.conf than when it is in .htaccess :
mod_rewrite said:
As you will see below, [tt]RewriteRule[/tt] can be used in per-directory config files ([tt].htaccess[/tt]). In such a case, it will act locally, stripping the local directory prefix before processing, and applying rewrite rules only to the remainder. When processing is complete, the prefix is automatically added back to the path.
Regarding the ignorance on the .htaccess file, I have no idea. Actually, neither Apache Tutorial: .htaccess files | Troubleshooting seems to have.


Feherke.
 
Have you tried:

RewriteRule ^/alice.html$ bob.html

(i.e a / in front of "alice")

I've had it before where that is required on some setups, but not others

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top