DijkeMark
DijkeMark

Reputation: 1306

My rewrite rule is not working

I need to make a rewrite rule for a page, but it does not work. I do have mod_rewrite for apache enabled

This is my .htacces file:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule ^gameofthrones/(full|house|characters)\.(all|Stark|Lannister)\.(html|xml|json)$ index.php?output=$3&house=$2&info=$1
</IfModule>

But when I enter this url: localhost/school/str-webservices/eindopdracht/index.php?output=html&house=all&info=full

It stays that way, but it should be something like: localhost/school/str-webservices/eindopdracht/gameofthrones/full/all/html

What am I doing wrong?

Thanks in advance,

Mark

Upvotes: 1

Views: 131

Answers (3)

htmlandrea
htmlandrea

Reputation: 111

I think it could be a directory problem:

  • where is the .htaccess file located in the directory tree?
  • where is the index.php located file?

If the index.php file is located in the same directory (I assume the same ./school/str-webservices/eindopdracht/) you have simply to add:

RewriteBase /school/str-webservices/eindopdracht/

after RewriteEngine On

I'm sorry if I don't understand the problem.

Bye.

Upvotes: 0

Seybsen
Seybsen

Reputation: 15572

Add another rule which actually redirects your non rewritten URLs to the rewritten form:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /school/str-webservices/eindopdracht/

    RewriteCond %{REQUEST_URI} ^school/str-webservices/eindopdracht/index\.php
    RewriteCond %{QUERY_STRING} ^output=([^&]*)&house=([^&]*)&info=([^&]*)$
    RewriteRule ^(.*)$ gameofthrones/%3.%2.%1? [R=301,L]

    RewriteRule gameofthrones/(full|house|characters)\.(all|Stark|Lannister)\.(html|xml|json)$ index.php?output=$3&house=$2&info=$1 [PT,NC,L]
</IfModule>

Then call: localhost/school/str-webservices/eindopdracht/index.php?output=html&house=all&info=full which should redirect you to: localhost/school/str-webservices/eindopdracht/gameofthrones/full.all.html

Upvotes: 1

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 174937

You are misunderstanding the concept of URL rewriting.

Let's say I rewrite /hello to index.php?get=hello. This means that index.php?get=hello will still work, but if I write /hello, it will, under the hood, map that to index.php?get=hello.

So while the user's address bar reads /hello, he's actually viewing index.php?get=hello.

That does not cancel index.php?get=hello, that doesn't mean that if anyone accesses the page through that URL it will redirect the user to /hello.

Upvotes: 1

Related Questions