0

I've got no idea how to properly use the .htaccess file and all the guides and tutorials out there aren't the easiest to understand.

Here is my current code...

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^/([^/]+)/([^/]+)/([^/]+)$ productpage.php?productidpage=$1&brand=$2&productname=$3 [L,NC]

I want it to display as www.mysite.com/$1/$2/$3/ whenever productpage.php is loaded.

Well, actually I want it to display as www.mysite.com/$2/$3 if that's possible.

The productidpage variable is what is picked up in the code to load the page, $2 and $3 are purely there just to modify the URL.

Jürgen Thelen
  • 12,745
  • 7
  • 52
  • 71
  • See [Tips for debugging .htaccess rewrite rules](http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules). – TerryE Aug 05 '12 at 11:37

2 Answers2

0

Try removing the leading slash in your regular expression. The leading slash in URI's are removed when matching the RewriteRule's expression when rules are in htaccess files.

# no slash---v maybe a slash here---v
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ productpage.php?productidpage=$1&brand=$2&productname=$3 [L,NC]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I removed the slash but it still didn't do anything. – user1576895 Aug 05 '12 at 05:18
  • @user1576895 oh, you're also missing the slash at the end of the expression (right before the `$`). – Jon Lin Aug 05 '12 at 05:20
  • grrr I put the slash in, no effect. It's just doing nothing, not even throwing out an error. But if I deliberately type crap in there it does throw out an error. – user1576895 Aug 05 '12 at 05:27
  • @user1576895 Are these the only rules in the htaccess file? Is this htaccess file in your document root? Does adding a slash in front of `productpage.php` help? – Jon Lin Aug 05 '12 at 05:31
  • no the slash in front of productpage didn't have any effect. I am using hostgator as my host. It's not my main domain, that has a wordpress install on it. This is another domain which I added and assigned a folder for that domains root dir. The .htaccess file is in there. I've also made a test.mysite.com subdomain which I am testing all this on, if that makes any difference. – user1576895 Aug 05 '12 at 05:42
  • @user1576895, your regexp will _never_ match with a leading / in an `.htaccess` context. It will match if you've constructed it correctly without it. Read the debugging tips Q&A that I pointed you at above. You also need to specify the correct `RewriteBase` in your subdomain `.htaccess` file. – TerryE Aug 05 '12 at 11:41
0

Make sure that AllowOverride FileInfo or (AllowOverride All) is set for the <Directory> containing your .htaccess files.

Then set RewriteLog and RewriteLogLevel at the server or virtual host level to debug your rewrite rules.

Update: I highly recommend you to check out Ask Apache - it has tons of mod_rewrite info and examples.

Dmitry Leskov
  • 3,233
  • 1
  • 20
  • 17
  • ^ Ok, where does all this have to go, in the .htaccess or the actual server settings. I am going into un charted territory here. – user1576895 Aug 05 '12 at 05:21
  • `AllowOverride` is recognized in global server settings, inside `` and inside ``. Rewrite logging can only be enabled for the entire server or for a specific virtual host. – Dmitry Leskov Aug 05 '12 at 05:52