Jump to content
Sign in to follow this  
real_illusions

Rewriting Urls With $_Get Variables

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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

Remember that it's case sensitive. You need to think of lowercase and uppercase characters: ^/([a-zA-Z]+)/?$

Share this post


Link to post
Share on other sites

Oh yes, forgot about that. But still nothing when adding in the a-z part. Have tried removing the '+' bit but again, 404 error. Same with removing the /?, or even just ? or /, all 404 errors.

Share this post


Link to post
Share on other sites

That's very strange. Not even the simplest rule is working?

Share this post


Link to post
Share on other sites

Other rules are working on the server (like non-www to www). Have taken off any [L]'s on other rules as that indicates its the last rule I believe, and still no joy.

Share this post


Link to post
Share on other sites

What does your entire htaccess file look like?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

I don't see anything wrong. Maybe the slash is the problem.Try this:

RewriteRule ^([a-zA-Z]+)/?$ location.php?area=$1 [NC,L]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...