John Smith
John Smith

Reputation: 363

Rewriting URL with .htaccess local in XAMPP

My .htacces begins with

   RewriteEngine on
   RewriteBase /

(I tried it also without RewriteBase...)

I tried all of the following rewriting rules to rewrite the URL

index.php?page=news

to

/blog

Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.

I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III

...into: blog/release/9-Beastie-Boys-III

I am lost. Hope you can help me.

Upvotes: 1

Views: 26911

Answers (3)

John Smith
John Smith

Reputation: 363

Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]

and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline

the solution is:

RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2

After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline

Upvotes: 2

Martin Burch
Martin Burch

Reputation: 2931

For your first question, try this:

RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news

Upvotes: 1

trejder
trejder

Reputation: 17505

First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.

For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.

I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]

On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.

Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.

Upvotes: 2

Related Questions