real_illusions Posted September 7, 2011 Share Posted September 7, 2011 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 More sharing options...
Ingolme Posted September 7, 2011 Share Posted September 7, 2011 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 More sharing options...
real_illusions Posted September 8, 2011 Author Share Posted September 8, 2011 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. Link to comment Share on other sites More sharing options...
real_illusions Posted September 21, 2011 Author Share Posted September 21, 2011 Anyone have any ideas or clues? Link to comment Share on other sites More sharing options...
real_illusions Posted September 21, 2011 Author Share Posted September 21, 2011 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 More sharing options...
Ingolme Posted September 21, 2011 Share Posted September 21, 2011 Remember that it's case sensitive. You need to think of lowercase and uppercase characters: ^/([a-zA-Z]+)/?$ Link to comment Share on other sites More sharing options...
real_illusions Posted September 21, 2011 Author Share Posted September 21, 2011 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. Link to comment Share on other sites More sharing options...
Ingolme Posted September 21, 2011 Share Posted September 21, 2011 That's very strange. Not even the simplest rule is working? Link to comment Share on other sites More sharing options...
real_illusions Posted September 22, 2011 Author Share Posted September 22, 2011 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. Link to comment Share on other sites More sharing options...
Ingolme Posted September 22, 2011 Share Posted September 22, 2011 What does your entire htaccess file look like? Link to comment Share on other sites More sharing options...
real_illusions Posted September 22, 2011 Author Share Posted September 22, 2011 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 More sharing options...
Ingolme Posted September 22, 2011 Share Posted September 22, 2011 I don't see anything wrong. Maybe the slash is the problem.Try this: RewriteRule ^([a-zA-Z]+)/?$ location.php?area=$1 [NC,L] Link to comment Share on other sites More sharing options...
real_illusions Posted September 22, 2011 Author Share Posted September 22, 2011 Woo, finally, it works! It was the slash that was the problem. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.