Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:41:02+00:00 2026-06-15T06:41:02+00:00

I am trying to do some URL rewriting with Apache and PHP. This is

  • 0

I am trying to do some URL rewriting with Apache and PHP. This is for SEO reasons so that foo.com/product-category/product-title becomes foo.com/product.php?id=999. I would of course want the URL not to change and be the SEO friendly version.

I have a current site which has a working setup but it’s very much a hack rather than a maintainable solution, so I am trying to do things right!

At the moment I have:-

RewriteRule ^([a-zA-Z0-9_\ \-\%]+)/?($) /url_redirect.php?page=$1 [QSA,L]

Which works perfectly, http://foo.com/random-url?foo=1&bar=2 ends up at /url_redirect.php with $_GET[‘page’] = ‘random-url’ and $_GET[‘foo’] = 1 etc etc..

I want the exactly the same thing to happen if you one level deeper
(eg http://foo.com/non-existing-directory/random-url?foo=1&bar=2)

I could make the non-existing-directoy a real directory and then .htaccess from there but there has to be a easer way.. I would prefer me not to have to hardcode any directory names (which is sort of how my current solution works).

I think the issue is probably something not right with the regular expression, they always defeat me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:41:04+00:00Added an answer on June 15, 2026 at 6:41 am

    I just tried this, might not be the best way to achieve it though (I’m no rewrite guru)

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_\ \-\%]+)/([a-zA-Z0-9_\ \-\%]+)?($) url_redirect.php?page=$2 [QSA,L]
    RewriteRule ^([a-zA-Z0-9_\ \-\%]+)/?($) url_redirect.php?page=$1 [QSA,L]
    

    Sorry that was for my local setup here’s how I think you would want it!

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_\ \-\%]+)/([a-zA-Z0-9_\ \-\%]+)?($) /url_redirect.php?page=$2 [QSA,L]
    RewriteRule ^([a-zA-Z0-9_\ \-\%]+)/?($) /url_redirect.php?page=$1 [QSA,L]
    

    Notice the / before url_redirect.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using http://www.asual.com/jquery/address/ plugin and trying to parse some url, this is what
I’m trying to write some encryption code that is passed through a Url .
I'm trying to rewrite some query strings I have in my URL like this
Im trying to get some auto complete to work. I have this URL i
We have an url like http://site.s3.amazonaws.com/images/some image @name.jpg inside $string What I'm trying to
I'm trying to setup a PHP website in IIS 7.0 with URL rewriting enabled
I've some url rewrites something like that: RewriteRule ^futbol-video/([^/]*)-([^-]*)\.html$ /html/video.php?text=$1&id=$2 [L] RewriteRule ^futbol-takimi/([^/]*)-([^-]*)\.html$ /html/takim.php?text=$1&id=$2
I'm trying to do some URL rewriting - but for some reason it's not
I'm trying to do some URL rewriting, but my host (1and1) and my little
I'm trying to send a URL with some parameters using HttpPost but it has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.