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 4553364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:56:09+00:00 2026-05-21T16:56:09+00:00

I’ve written some code on my .htaccess file which allows the use of SEO

  • 0

I’ve written some code on my .htaccess file which allows the use of SEO friendly URLs instead of ugly query strings. The following code rewrites the SEO friendly version in the browser to the query string version on the server.

RewriteEngine On
RewriteRule ^seo/([^/]*)/$ /directory/script.php?size=large&colour=green&pattern=$1 [L]

So that the ugly

http://www.mysite.com/directory/script.php?size=large&colour=green&pattern=striped

Is now beautiful

http://www.mysite.com/directory/seo/striped/

Just to explain the code a bit; seo is there to add more keywords to the URL, /directory/ is the directory in which the .htaccess file is located, parameters size=large and colour=green never change, while pattern=$1 can be many different values.

The above code works perfectly. However, the problem is I am now stuck with two URLs that point to exactly the same content. To solve this, I would like to 301 redirect the old, ugly querystrings to the SEO friendly URLs. What I have tried so far does not work – and Google is not being particularly friendly today.

Can anybody offer working code to put in my .htaccess file that redirects ugly to new URL, while retaining the rewrite? Thanks!

  • 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-05-21T16:56:09+00:00Added an answer on May 21, 2026 at 4:56 pm

    This should do the trick:

    RewriteEngine On

    ## Redirect to pretty urls
    # The '%1' in the rewrite comes from the group in the previous RewriteCond
    RewriteCond %{REQUEST_URI} !seo
    RewriteCond %{QUERY_STRING} ^size=large&colour=green&pattern=([a-zA-Z]*)$
    RewriteRule (.*) /directory\/seo\/%1\/? [L,R=301]
    
    ## Rewrite to long url, additional parameter at the end will cause
    ## the internal redirect not to match the previous rule (would cause redirect loop)
    RewriteRule ^directory\/seo\/([^/]*)/$ /directory/script.php? size=large&colour=green&pattern=$1&rewrite [L]
    

    You can also match the size and colour if needed, by changing those to regex groups as well, and using the corresponding %N

    Hope this helps.

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

Sidebar

Related Questions

I have written some code which sends queries to google and returns the query
I've written some code which is a mini simple imitation of messenger program. In
Hi ive written some code to connect to a server through the use of
I have written some code which produces simple animations based on cycling through a
I have written some code which passes values between java and c using jni.
I've written some code to output any IEnumerable collection to a file, but can't
I've written some code in C for converting strings passed from VBA, when the
I've written some code in Javascript which needs some transformation but I don't know
i written some code in JSP like this-- <input type=file name=imagename > and in
I have just written some code, which as i was writing i thought, this

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.