0

So I wish to rewrite my website URL. I've tried several .htaccess generators, and understanding the basics of .htaccess, however, without any luck! So I was wondering if someone in here might help me.

I have a website with the address: http://www.example.com

I have a navigation menu with several links pointing to for example:

http://www.example.com/?page=services

How can I rewrite this to:

http://www.example.com/services

I have 5 pages, and I also wish to rewrite:

http://www.example.com/?page=blog&article=12342

Into this:

http://www.example.com/blog/12342

I dont wish to unable my $_GET['page'] function whilst doing this.

Gjert
  • 1,069
  • 1
  • 18
  • 48
  • From what you're saying, rewriting probably works exactly the other way around than you're thinking. Have a look at the duplicate. Let me know if that didn't answer your question and possibly add more information to your question why it didn't. – deceze Mar 25 '15 at 20:41
  • @deceze Oh, this was helpfull, thank you. However I still struggle with finding out how I can make `RewriteRule (.*) index.php?url=$1` work for more than 1 variable. – Gjert Mar 25 '15 at 20:47
  • It's typically best to have *routing* implemented in PHP. Meaning, you do a general `RewriteRule (.*) index.php?url=$1`, then in `index.php` you `explode` `$_GET['url']` by `/` and figure out which page you want. Best use an existing *router* for that instead of reinventing the wheel. – deceze Mar 25 '15 at 20:49
  • Otherwise you need a lot of individual rewrite rules: `/blog/(\d+) index.php?page=blog&article=$1`... – deceze Mar 25 '15 at 20:50
  • @deceze `` Does this seem correct to you if I use your rewrite rule? – Gjert Mar 25 '15 at 20:56
  • *Something* like that, though this won't work as is since `explode` returns an array and not a string. Again, I'd recommend you look into *routing*, it's a thing. – deceze Mar 25 '15 at 20:57
  • @deceze, I can't get it to work... Could you help me out with it? I've tried looking into routing and the link you posted as similar post. However, my website wont load properly when rewriting... I get the correct $_GET variable. However, the rest of the page (images, spreadsheet)++ will not load. This is what my page looks like: http://gogetit.no/ and this is with the rewrite code: `RewriteRule (.*) index.php?page=$1` – Gjert Mar 25 '15 at 21:22

0 Answers0