1

I have viewed similar questions to mine, but it does not pertain to my specific example.

1st URL (what is to be sent to the server and is originally inputted to the URL bar): www.site.com/?variable1=3&variable2=filename.php

2nd URL (what is shown to the user in the URL bar): www.site.com/filename.php

where "filename.php" is the same value as "variable2" in the original URL.

I have seen examples of the opposite, where someone enters the 2nd URL and it replaces it with the 1st URL, but that's not what I want.

Currently what I have:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule    ^/([A-Za-z0-9]+)$    /?CommID=$1&FileName=$2    [NC,L]

which I got the structure from the link provided from this question, but that's not working.

I'm not trying to redirect, just mask the current URL so it is SEO friendly. I need to grab both variables from the URL to have the dynamic content be pulled correctly.

Any ideas?

Community
  • 1
  • 1
Oneag
  • 93
  • 1
  • 1
  • 5

1 Answers1

1

Try adding the following to your .htaccess file in the root of your domain

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

#if the query string has a commid and a fIlename Param
RewriteCond %{QUERY_STRING} ^CommID=([^&]+)&FileName=([^&]+) [NC]
#redirect users to the Pretty URL of www.site.com/variable1/filename.php
RewriteRule .* /%1/%2? [L,R=301]

#for a URL like this in address bar www.site.com/variable1/filename.php
#CommID will contain variable1 and FileName will contain filename.php
RewriteRule    ^([A-Za-z0-9]+)/([A-Za-z0-9\.]+)$    /?CommID=$1&FileName=$2    [NC,L]

Edit: Also redirect users using the query string URL to the pretty URL

Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31
  • The URL still shows www.thesite.com/?CommID=3&FileName=about-us.php. – Oneag Dec 13 '11 at 13:12
  • It is very close! It does redirect to the pretty URL correctly, but it throws a redirect loop error in the browser. This URL is what it gives: www.thesite.com/3/about-us.php?CommID=3&FileName=about-us.php – Oneag Dec 13 '11 at 14:42
  • I forgot to add a `?` in the first RewriteRule to remove the original query string params. That will stop the loop – Ulrich Palha Dec 13 '11 at 14:47
  • Technically, it is working that way it is, but it's looking for about-us.php, which doesn't exist. I just wanted the URL to "mask" the original URL (process the 1st URL and then "show" the 2nd URL. Is that not possible? – Oneag Dec 13 '11 at 14:53
  • For this original question, this is the right answer, but my solution ended up being: RewriteEngine on RewriteRule ^([^/\.]+)/?$ ?FileName=$2 [L] – Oneag Dec 13 '11 at 21:16