0

Changed my url from

http://www.website.com/b.php?n=45&t=example

to this

http://www.website.com/45/example

by using this mod_rewrite

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/(.*) /b.php?n=$1&b=$2 [L,QSA]

How do I get my query strings to still work because I want to use $_GET

echo '<img src="gifs/' . $_GET["t"] . '/' . $_GET["n"] . '.gif">';
7
  • 1
    Can you explain exactly what your problem is? In what way does $_GET not contain what you want? Is it simply that n=$1&b=$2 should be n=$1&t=$2? Commented Aug 24, 2012 at 11:11
  • 1
    If you rewrote the URL correctly, you should be able to access $_GET['n'] and $_GET['t'] just the same as always. Have you tried accessing those vars? Commented Aug 24, 2012 at 11:12
  • Yes, [QSA] should allow you to get the query string still? In this case you can rebuild the GET array based on the $_server variables. Commented Aug 24, 2012 at 11:12
  • @mario Hey I thought this was a better question from what I learnt last time! Sorry buddy Commented Aug 24, 2012 at 11:24
  • @tomhallam I have added my $_GET code to get the image Commented Aug 24, 2012 at 11:25

1 Answer 1

1

You can use the following .htaccess code for sending the full url to the b.php file and there you can split the url using the explode function and can get the query strings separately

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/* b.php?url=%{REQUEST_URI} [L,NC,QSA]
Sign up to request clarification or add additional context in comments.

1 Comment

So I just add this onto my .htaccess and then what do I do. I am not sure what you mean by explode function? Cheers buddy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.