No joy with mod rewrites

New to mod_rewrite? This is a good place to start.

No joy with mod rewrites

Postby griffen » Sat Oct 03, 2009 8:11 am

Hi there,

I'm having real problems getting mod rewrites to work.

I have enabled them in apache and they're appearing as loaded modules in phpinfo.

I'm trying the most simplest mod rewrite in the land without any joy....I think.

Trying to rewrite:

localhost/test/

to

localhost/test.php

.htaccess file looks like:

RewriteEngine On
RewriteRule ^test/?$ test.php

Anyone know what I'm doing wrong?
griffen
 
Posts: 5
Joined: Sat Oct 03, 2009 8:06 am

Postby richardk » Sat Oct 03, 2009 8:22 am

Try this mod_rewrite test.

Have you set AllowOverride to All in the <Directory> for your document root in your httpd.conf file? FAQ: How to enable mod_rewrite.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby griffen » Sat Oct 03, 2009 8:34 am

Did the override previously without any joy.

The test worked though :)

So I tried something a little bit more adventurous....

Options +FollowSymLinks

RewriteEngine On

//RewriteRule modrewrite http://localhost/test.php [NC,R,L]
RewriteRule ^(.+)\.html$ $1.php [L]


Put:

localhost/test.html
into a browser
Got an Error 500

No joy and not sure why it's not working.

Any ideas?
griffen
 
Posts: 5
Joined: Sat Oct 03, 2009 8:06 am

Postby richardk » Sat Oct 03, 2009 10:43 am

What does your Apache error_log say is causing the error?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby griffen » Sat Oct 03, 2009 11:40 am

Checked the error log and it all seems a little strange.

Coming back with:

[Sat Oct 03 17:32:10 2009] [alert] [client ::1] C:/xampp/htdocs/.htaccess: Invalid command '//RewriteRule', perhaps misspelled or defined by a module not included in the server configuration

Any ideas?
griffen
 
Posts: 5
Joined: Sat Oct 03, 2009 8:06 am

Postby richardk » Sat Oct 03, 2009 12:41 pm

Right, comments in .htaccess files start with a #.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby griffen » Sun Oct 18, 2009 11:20 pm

Hi Richard,

Thanks for your help. Worked a treat and I feel a little stupid :(

Anyway happy days
griffen
 
Posts: 5
Joined: Sat Oct 03, 2009 8:06 am

VISTA problem

Postby halfbeep » Sat Nov 28, 2009 3:32 pm

On Vista with Apache 2.2.14 i'm still getting no errors and no re-rewrite with the following config, at the coomand line:-

c:\home\Apache2.2\bin>httpd -M
Loaded Modules:
core_module (static)
win32_module (static)
mpm_winnt_module (static)
http_module (static)
so_module (static)
rewrite_module (shared)
alias_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
mime_module (shared)
php5_module (shared)
Syntax OK

httpd.conf :-

<IfModule rewrite_module>
RewriteEngine On
RewriteLog logs/rewrite.log
RewriteLogLevel 5
</IfModule>

<Directory "C:/home/www/test">
Options ExecCGI FollowSymLinks Includes MultiViews
AllowOverride All
Order allow, deny
RewriteRule ^alice\.html$ bob\.html
</Directory>

in the browser:-
http://192.168.0.6/test/alice.html
produces:-
This is Alice's webpage

in the browser:-
http://192.168.0.6/test/bob.html
produces:-
This is Bob's webpage
halfbeep
 
Posts: 1
Joined: Sat Nov 28, 2009 3:28 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 5 guests

cron