• 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

    • Sorry to be that guy but, Given Trump won again even after a failed first term it would appear attacking the other side is how to gain Government in America. Voters when it came down to it didn't give a s**t about those Democratic achievements and voted for Trump over an intelligent, qualified mixed race woman. We need to face up to this uncomfortable reality. There are more Americacan voters who support racism and christian bigotry along with defending and supporting pedophilia, adjudicated rapists, multiple time convicted felons etc than those who don't. Btw, that is how the world sees America now. Not that Trump voters care as they attempt to cocoon themselves in a **** bubble.
    • That's not clickbait. Clickbait is headlines like, "You'll never guess what this person looks like now" for example. For goodness sake, take a look around the internet if you think this is clickbait. How do sites survive if people don't click through to articles? How many people in all honesty would have clicked this if it had your suggested headline? You and those upvoting your post won't be happy until the web is a couple of hundred websites all behind a paywall.
    • HopToDesk 1.46.2.0 by Razvan Serea HopToDesk aims to improve the user experience by providing a free, easy-to-use, and secure remote desktop solution for all major device types including Windows PC, Mac, Linux, Android, Chrome Books, iOS, and even Raspberry Pi devices. HopToDesk empowers you to connect, control, and collaborate with ease. Whether you're providing IT support, managing remote teams, or accessing your own devices from anywhere, HopToDesk offers a reliable and secure solution. HopToDesk does not and cannot monitor user activity as the application uses end-to-end encryption for all traffic, and does not make a distinction between personal and business use (both are allowed). Additionally, HopToDesk includes many of the main features of common remote desktop solutions such as Unattended Access, File Transfer, Live Chat, Wake-On-LAN, 2FA, Direct IP access, a Recent Session and Favorite list, and is available in over 20 languages. HopToDesk can run in portable mode or installed on desktop operating systems. Installation is optional, and will install the HopToDesk service which runs in the background and listens for incoming connections, allowing the device to be accessible at all times. Why Choose HopToDesk? Completely Free: Enjoy full access for both personal and commercial use—no hidden fees or limitations. End-to-End Encryption: All communications, including screen sharing, file transfers, and chats, are protected with robust encryption. Open Source: Contribute to and benefit from a transparent and community-driven project. No Account Required: Connect instantly without the need for sign-ups or subscriptions. Core Features Remote Control & Screen Sharing: Effortlessly access and manage remote devices. File Transfer: Securely send and receive files with drag-and-drop simplicity. Live Chat: Communicate in real-time during sessions. Multi-Monitor Support: Navigate multiple screens with ease. Clipboard Synchronization: Copy and paste seamlessly across devices. Wake-on-LAN: Power on remote systems remotely. Session Recording: Document sessions for future reference. Two-Factor Authentication: Enhance security with an additional verification layer. Custom Branding: Personalize your remote sessions with custom avatars. Unattended Access: Connect to devices without requiring user intervention. Network Customization: Adjust settings like TURN relays and signaling servers to suit your environment. Centralized Device Management Utilize the HopToDesk Dashboard to: Monitor device status in real-time. Generate invite links for easy device integration. Customize network settings and synchronize changes effortlessly. Add a personal touch with custom avatars displayed during remote sessions. Download: HopToDesk 64-bit | HopToDesk 32-bit | ~9.0 MB (Freeware) Download: HopToDesk ARM64 | 21.4 MB Link: HopToDesk Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Or use Epic games and get full games for free. lol Steam and their demos. Thankfully there’s competition
    • Maybe I missed it, but does this say anywhere that the game save bug has been squashed? I haven't encountered it myself, but it would be nice to know I'm good to go. Anyway, amazingly well done game. Mostly more of the same. ...but when the same is best in class with improved graphics and features, then a win.
  • Recent Achievements

    • Reacting Well
      Almohandis earned a badge
      Reacting Well
    • First Post
      Cosminus earned a badge
      First Post
    • One Year In
      ThatGuyOnline earned a badge
      One Year In
    • Week One Done
      Jeroen Wilms earned a badge
      Week One Done
    • Week One Done
      rolfus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      482
    2. 2
      +Edouard
      181
    3. 3
      PsYcHoKiLLa
      119
    4. 4
      Steven P.
      84
    5. 5
      neufuse
      73
  • Tell a friend

    Love Neowin? Tell a friend!