c_pattle Posted June 23, 2011 Share Posted June 23, 2011 I have the following in my .htaccess file. RewriteEngine on Options -Indexes #Re-write rules RewriteRule ^/([A-Za-z0-9]+)$ $1.php RewriteRule colour/([A-Za-z0-9]+)$ index.php?colour=$1 RewriteRule article/([0-9]+)$ article.php?number=$1 My first two rewrite rules work but the last one doesn't. I want the url - article.php?number=1 - to be replaced with - article/1. At the moment the redirect still takes me to the article.php page but the "number" variable seems to not be defined. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/ Share on other sites More sharing options...
cags Posted June 24, 2011 Share Posted June 24, 2011 You mean $_GET['number'] is empty? The code you have looks correct. You could add [R=302] as a temporary measure to see where the URL is getting forwarded to. Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234187 Share on other sites More sharing options...
c_pattle Posted June 24, 2011 Author Share Posted June 24, 2011 Yeah the "$_GET['number']" variable is empty. The url seems to be redirecting to the right file but for some reason that variable is empty. Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234458 Share on other sites More sharing options...
wildteen88 Posted June 24, 2011 Share Posted June 24, 2011 Try disabling multiviews Options -Indexes -Multiviews Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234464 Share on other sites More sharing options...
c_pattle Posted June 25, 2011 Author Share Posted June 25, 2011 Thanks, what does that do. I tried it but it seems to make all of the links on my site now work. Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234641 Share on other sites More sharing options...
wildteen88 Posted June 25, 2011 Share Posted June 25, 2011 multiviews allows you to call for files without stating their extension. When it is enabled you can call site.com/about.php using site.com/about Explanation from the manual A MultiViews search is enabled by the MultiViews Options. If the server receives a request for /some/dir/foo and /some/dir/foo does not exist' date=' then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document.[/quote'] Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234651 Share on other sites More sharing options...
c_pattle Posted June 25, 2011 Author Share Posted June 25, 2011 Ah okay. I made a mistake on my previous post. I meant to say that it makes all of my links "not" work rather than "now" work. Do you know why thats happening? Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234689 Share on other sites More sharing options...
wildteen88 Posted June 25, 2011 Share Posted June 25, 2011 What do you links look like? Also in order for this rule to work RewriteRule ^/([A-Za-z0-9]+)$ $1.php You need to remove the forward slash. Quote Link to comment https://forums.phpfreaks.com/topic/240232-rewrite-not-working/#findComment-1234720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.