Jump to content

Rewriting Urls With $_Get Variables


real_illusions
 Share

Recommended Posts

Hi, If I have a page URL like this: example.com/page.php?variable=somethingexample.com/page.php?variable=something-goes-here Then how do I get it to show example.com/somethingorexample.com/something-goes-here via .htaccess? And would it still work? As in, would the browser pickup the variable and display the right content? Or is there a better way of doing this? Thanks.

Link to comment
Share on other sites

Using the [QSA] modifier, you can include the query string in your rewrite rules.Use the [R] rule to redirect. I haven't checked to make sure I have the syntax right, but something like this should work

RewriteRule ^page.php?page=(.*)$ /$1 [QSA,R=301]

You'll also need another rewrite rule that turns the other URL back into the query string you wanted.

Link to comment
Share on other sites

Cant make it do what I want it to. Found a few online generators but none seem to either do the trick I want or the code they product doesn't work. It doesn't produce a 500 error, it just produces a 404 error on the friendly url. Stuff like:RewriteRule /(.*) /page.php?page=$1 [PT] Even hard coding it this way doesnt work: RewriteRule ^/Something$ page.php?variable=Something And yes Rewrite Engine is on.

Edited by real_illusions
Link to comment
Share on other sites

  • 2 weeks later...

I have this: RewriteRule ^/([A-Z]+)/?$ location.php?area=$1 [NC,L] Which doesn't create a 500 server error, but I still 404's when trying to access /areagoeshere for example. The underlying url is location.php?area=areagoeshere Why is it doing this?

Link to comment
Share on other sites

Have put in example.co.uk instead of the actual URL, and replaced a couple of page file names, and xx'd out the IP address that was causing problems.

<Files .htaccess>order allow,denydeny from all</Files>  ErrorDocument 400 /error400.phpErrorDocument 401 /error401.phpErrorDocument 403 /error403.phpErrorDocument 404 /error404.phpErrorDocument 500 /error500.php DirectoryIndex index.php  RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.co.uk/.*$ [NC]RewriteRule \.(gif|jpg)$ http://www.example.co.uk/dontsteal.gif [R] redirect 301 /oldpageone.php http://www.example.co.uk/newpageone.phpredirect 301 /oldpagetwo.php http://www.example.co.uk/newpagetwo.phpredirect 301 /oldpagethree http://www.example.com/newpagethree.php  order allow,denydeny from xx.xx.xx.xxallow from allRewriteCond %{HTTP_HOST} ^example\.co.ukRewriteRule (.*) http://www.example.co.uk/$1 [R=301]  RewriteRule ^/([a-zA-Z]+)/?$ location.php?area=$1 [NC,L]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...