• 0

Search Engine Friendly URLs


Question

Hello,

I am trying to learn how to use Search Engine Friendly URLs and I've come this far.

I can turn an url like this: http://localhost/index.php?a=1 into this http://localhost/area/1/

thanks to this code in a .htaccess file:

RewriteEngine On
#RewriteRule ^area/(.*)/$ index.php?a=$1 [L]

What I am trying to do is to turn an url like this:

http://localhost/index.php?a=1&b=2&amp...blah=y&hi=z

into something like this:

http://localhost/area/1/b/2/c/3/something/x/blah/y/hi/z/

How can I do this if possible?

Link to comment
https://www.neowin.net/forum/topic/700482-search-engine-friendly-urls/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Drupal does this.

For example this site I made.

It turns http://www.chirohoepertingen.be/index.php?q=node/114

into http://www.chirohoepertingen.be/node/114

Then, in PHP, you can split up the values between the /'s to seperate values. I'm not at home right now, but I'll check the source code to see if I can get you a code up and running in PHP/.htaccess

  • 0

What you ask is certainly possible. On the left of the RewriteRule you have a regular expression representing the URL the clients request, and on the right, the transformation to a real URL the server can retreive. See the '$1' in the transformation? It grabs whatever is in the first set of brackets in the regex. Likewise, if you had a second pair of parenthesis, you would use $2 to grab that information, and so on. This should let you write your longer rules.

  • 0
What you ask is certainly possible. On the left of the RewriteRule you have a regular expression representing the URL the clients request, and on the right, the transformation to a real URL the server can retreive. See the '$1' in the transformation? It grabs whatever is in the first set of brackets in the regex. Likewise, if you had a second pair of parenthesis, you would use $2 to grab that information, and so on. This should let you write your longer rules.

What if I don't know how many $ I will have?

What do I have to write in RewriteRule so I can have an url like mentioned above and without knowing the amount of $?

  • 0

RewriteEngine On
RewriteBase /
RewriteRule areaone/page-(.*).html$ index.php?a=1&p=$1 [L]
RewriteRule areatwo/page-(.*).html$ index.php?a=2&p=$1 [L]
RewriteRule areatwo/page-(.*)-tourpage-(.*).html$ /index.php?a=2&p=$1&t=$2 [L]

a= area

p= page

t= tour page (inside one page (5) and area (2))

What I am trying to do is to transform a link like this:

http://www.mysite.com/index.php?a=3&p=5

into this:

http://www.mysite.com/areathree/page-5.html

Everything is ok so far.

But now, I need to add an extra variable to the URI which doesn't allways appear, only on the page 5, so the url needs to be like this:

http://www.mysite.com/areatwo/page-5-tourpage-1.html

I tried to use the third RewriteRule as in the above example and it only works if I comment the second RewriteRule...

How can I fix this?

Thanks! :beer:

  • 0

You'd need to put that third rewrite rule before the second. Basically the process is getting 3rd example, but the regex check is being satisfied by the 2nd rewrite rule. Change it to this:

RewriteEngine On
RewriteBase /
RewriteRule areaone/page-(.*).html$ index.php?a=1&p=$1 [L]
RewriteRule areatwo/page-(.*)-tourpage-(.*).html$ /index.php?a=2&p=$1&t=$2 [L]
RewriteRule areatwo/page-(.*).html$ index.php?a=2&p=$1 [L]

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Yeah, this is absolutely nothing new and EA have done it before. Burnout Paradise, released in 2008, had dynamic advertising billboards that were updated via the internet and targeted people based on location and what EA knew about them from their profile. It was particularly notable for the fact that the Obama presidential campaign ran ads in the game, in an attempt to reach a younger audience who didn't watch broadcast TV any more. It was by no means the first though. Battlefield 2142 from 2006 had the same thing. In fact, Neowin wrote a story about it back then. https://www.neowin.net/news/ba...-in-game-ads-clarification/
    • This is obviously aimed at the education where Apple has lost so much ground to Chromebooks in the last few years, but unless they come up with a comparable management system for education why would anyone switch back?
    • Here's how we arrived at that claim: Note that this is just Play Store downloads. The app is also available on the Galaxy App Store
    • Google Play states the app had more than 50 million downloads. What other metric do you suggest should be used?
    • MSN defined our generation in some ways, kind of like Snapchat and TikTok have done for future generations. I have great memories of the MSN era in the late 90s / early 2000s. In the UK everyone seemed to come home from School and go on MSN for the evening. We didn't really have mobile phones then, so other than going and knocking on your friends door it was a totally new way of interacting with people. I also loved how I could talk to people I’d met playing online games from around the world. Inviting people to NetMeeting and messing about with the shared white board and webcams was pretty fun, even if webcams only ran at a couple of fps over dial-up. All the random things you could do with MsgPlus! were really fun - I suspect that made a few people jump with /shello randomly blasting Mr Hankey out their speakers! Maybe I’m just nostalgic, however I do feel the internet and computers were more fun back then.
  • Recent Achievements

    • One Year In
      Console General earned a badge
      One Year In
    • One Year In
      Twozo Technologies earned a badge
      One Year In
    • One Month Later
      Twozo Technologies earned a badge
      One Month Later
    • Week One Done
      Twozo Technologies earned a badge
      Week One Done
    • Veteran
      branfont went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      531
    2. 2
      +Edouard
      205
    3. 3
      PsYcHoKiLLa
      132
    4. 4
      Steven P.
      90
    5. 5
      neufuse
      75
  • Tell a friend

    Love Neowin? Tell a friend!