Jump to content

mod_rewrite


laanes

Recommended Posts

Hi,

 

I started reading a tutorial on using .htaccess but got stuck at the very beginning.

 

Nothing seems to work, no matter what i write into the file.

 

I have placed it into my WAMP servers root folder and copied examples from the tutorial to test.

 

I can see that it is enabled in the apache modules list and it is loaded via the httpd conf file.

 

How could i get this thing to work?

 

 

Link to comment
Share on other sites

There is nothing specific that i am trying to do with it yet, just dropping in examples i can find on the web, like changing the default index page to something.html etc.

 

If i put absolute nonsens into the .htaccess, i get:

 

Internal Server Error

 

The server encountered an internal error or misconfiguration and was unable to complete your request.

 

Please contact the server administrator, admin@127.0.0.1 and inform them of the time the error occurred, and anything you might have done that may have caused the error.

 

More information about this error may be available in the server error log.

 

Link to comment
Share on other sites

I am using this rule:

 

RewriteEngine on

RewriteRule cat/(\w+)$ cat=$1

 

Result:

 

Both of these URLs work:

 

http://localhost/urls/cat/mickey

http://localhost/urls/urls.php?cat=mouse

 

I thought the URL will be rewritten when there is a pattern match,  in the current case - cat/mickey should be rewritten to cat=mickey ?

 

In fact, even http://localhost/urls/urls.php/cat/and/mouse/are/having/a/fight/over/bacon does not give an error, instead,  it is still displaying the content of http://localhost/urls/urls.php

 

What am i missing?

Link to comment
Share on other sites

Your rewrite rule is incorret, it should be

RewriteRule cat/(\w+)$ urls.php?cat=$1

Mod rewrite will not rewrite your existing links within your files. You'll need to change say

<a hef="urls.php?cat=whatever">whatever</a>

to

<a hef="/cat/whatever">whatever</a>

Yourself.

 

If you went to http://localhost/urls/urls.php?cat=mouse it will not redirect the user to http://localhost/urls/cat/mouse

 

In fact, even http://localhost/urls/urls.php/cat/and/mouse/are/having/a/fight/over/bacon does not give an error, instead,  it is still displaying the content of http://localhost/urls/urls.php

That is because that is infact a valid url

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.