Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite simple test script?

         

XtendScott

1:53 am on Feb 3, 2005 (gmt 0)

10+ Year Member



I have a WordPress blog on a server and the script given by WP is not working. The host is saying the Mod_rewrite module is on and loaded.

I don't know regex very well and wondering if someone had a simple script that I could use to test.

Example: mysite.com/check/1.php --> mysite.com/index.php.

I just want to be able to confirm that a simple script will work. The host is not familiar with the mod_rewrite.(PS host is a brother of a friend that I decided to put a couple sites on)

Thanks.

XtendScott

jdMorgan

4:00 am on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am so pleasantly surprised that anyone would think to start off with something simple! :)

So here's a freebie (See our charter for explanation):


# Set up mod_rewrite
Options +FollowSymLinks
RewriteEngine on
#
# Rules follow
#
# For use in httpd.conf (server configuration):
RewriteRule [b]^/c[/b]heck/1\.php$ /index.php [L]
#
# For use in .htaccess (per directory)
RewriteRule [b]^c[/b]heck/1\.php$ /index.php [L]

Jim

XtendScott

3:54 am on Feb 4, 2005 (gmt 0)

10+ Year Member



jdMorgan,

I do appriciate the script and it was my intention to make it as simple as possible for someone who knew what they were doing, as I do not mean to have others do my homework for me.

The requested URL /check/1.php was not found on this server.
Apache/2.0.46 (CentOS) Server at www.domain.com Port 80

With this response I should be able to assume that the mod_rewrite is not functioning. I did put this on a server where I know the mod_rewrite is working and it did work properly.

Thanks again, as I now have some verification for the host that it is not working properly.

Xtendscott

Marino

10:02 am on Feb 6, 2005 (gmt 0)

10+ Year Member



Hello,

It seems to be a path error. May be just a missing

RewriteBase /

directive after the RewriteEngine directive?

XtendScott

4:35 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



Marino, thanks for your suggestion, it also did not help correct the issue.

The host is saying that the Mod_rewrite is working because they had setup a 301 redirect in httpd.conf for domain.com -> www version of the domain.

Does a 301 in httpd.conf use the mod_rewrite? If so is there a way that the httpd.conf work and not the .htaccess?

jdMorgan

8:27 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A domain redirect would require mod_rewrite. But it sounds like they have not allowed you to use mod_rewrite, probably through their AllowOverride and Options config settings (See Apache core documentation). You'll have to pursue this with your host -- or switch hosts (I just went through this exercise, myself).

Jim

Skeleton

2:43 am on Feb 27, 2005 (gmt 0)

10+ Year Member



hi, i am a newbie to mod_rewrite. i tried the above .htaccess example to my existing site. when i called 'www.mysite.com/check/1.php' it showed me the index.php content as it should.

but my problem here is that my index php uses <img src="images/image.gif"...bla bla /> and when i called 'check/1.php' my index.php searches the images in 'www.mysite.com/check/images/image.gif' altough actual image files stand in 'www.mysite.com/images' directory. (this problem can be solved simply by using the actual image paths rather than relative ones but is there any other way?)

This is not the way i will use the mod_rewrite but trying to understand the logic. Thanks

jdMorgan

4:22 am on Feb 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Skeleton,

Welcome to WebmasterWorld!

The solution is to use <img src="/images/image.gif"

This is still a "relative" path, but it is relative to the site's root (home page) directory, instead of relative to the current page.

Jim

Skeleton

8:39 am on Feb 27, 2005 (gmt 0)

10+ Year Member



oh my goodness :) this was so simple, sorry for messing up :) thanx