News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

I'm a N00b to Rewrite, Please help me...

Started by misteraod, March 20, 2006, 04:03:55 PM

Previous topic - Next topic

misteraod

Hi there,

I want my visitor to just enter a direct link let say:
1... mydomain.sth/internet-miku-yoyo.html  or
2... mydomain.sth/semm-miku.html


As I upload my file at
3... mydomain.sth/doc/int_miku/internet-miku-yoyo.html  or
4... mydomain.sth/doc/int_miku/semm-miku.html


I just want the link in 1... point to 3... and 2... point to 4... respectively with rewrite, is it possible?

I try the following code:
RewriteEngine On
RewriteBase /

RewriteRule ^(.+)miku(.+)\.html$ doc/int_miku/$1miku$2.html  [L]


But it gave me only a headache... 500 Internal server error :( What can I do or do I miss something? ???

Thx.

webzone (archived)

There is a 500 error because your rule causes an infinite loop:

1. Rewrite /internet-miku-yoyo.html to /doc/int_miku/internet-miku-yoyo.html
2. Rewrite /doc/int_miku/internet-miku-yoyo.html to the same thing (and it keeps doing this forever).

The easy way to fix the problem is to rename your directory and files to not use the word "miku" (ie. use /doc/int/internet--yoyo.html).

The other way to do it would be to change your RewriteRule to:
RewriteRule ^([^/]+)miku([^/]+)\.html$ doc/int_miku/$1miku$2.html [L]

misteraod

Webzone, You rule!

Thx a million!

Another question if I apply thess rules:
1.. RewriteRule ^([^/]+)miku([^/]+)\.html$ doc/int_miku/$1miku$2.html [L]
2.. RewriteRule ^([^/]+)miku\.html$ doc/int_miku/$1miku.html [L]
3.. RewriteRule ^miku([^/]+)\.html$ doc/int_miku/miku$1.html [L]


Do they redundant? as only 1.. could not handle 2.. and 3.. requests - it gave me a 404 page not found.

mydomain.sth/semm-miku.html  --> 404
mydomain.sth/miku-goblet.html --> 404
mydomain.sth/internet-miku-orja.html --> work great  :D

Are there any other better ways to RewriteRule or just like that?

Thx.

webzone (archived)

I guess you could also try this one. It should combine rules 1 to 3.

RewriteRule ^([^/]+)?miku([^/]+)?\.html$ doc/int_miku/$1miku$2.html [L]

misteraod

#4
It works like a charm.  Thank you :)

Anyhow, do you have any suggestion on Rewrite tutorial website.  I read one from apache it's awesome but hard to undersatand.

webzone (archived)

QuoteAnyhow, do you have any suggestion on Rewrite tutorial website.  I read one from apache it's awesome but hard to undersatand.

Well, I started by learning how the PHP regular expressions work. Then, I learned the rest from the documentation on apache.org. It is mostly technical, but I got to understand how it worked with a lot of trial-and-error.