2

My mates and I are putting the finishing touches on our website hosted with ipage but we are just having one small issue with our .htaccess.

We want to make our urls SEO friendly (and neat) and the rewriterule is not working, we keep getting 404 errors. I just want to verify the syntax is correct. I have questioned it with ipage and they said mod_rewrite is installed and allowoverride all is set but couldn't help with the regular expression.

The url is:

http:// www.example.com/article.php?title=Some-Article

and we want to make it:

http:// www.example.com/Some-Article

the entire htaccess file:

# Protect db_connect
<files db_connect.php>
order allow,deny
deny from all
</files>

# Protect .htaccess
<files .htaccess>
order allow,deny
deny from all
</files>

Options +FollowSymLinks 
Options +Indexes
RewriteEngine On

# Remove .php but still allow addressing .php
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^([^/]*)/$ /article.php?title=$1 [L]

Any help would be greatly appreciated as I have searched for hours and also tested the syntax generated from http://www.generateit.net/mod-rewrite/ with no luck.

Regards,

Adam

Adam First
  • 435
  • 1
  • 4
  • 19
  • You should make the `/` optional ! `RewriteRule ^([^/]*)/?$ /article.php?title=$1 [L]` – HamZa Jun 02 '13 at 22:53
  • I added the ? to the regular expression, it gave me a 500 error across the whole site? – Adam First Jun 02 '13 at 23:06
  • What's the error? (See the log.) Also you can enable tracing and debugging of your rewrite rules to see what's going on. – Qtax Jun 02 '13 at 23:11
  • Cheers, I'm trying to find the proper error log (ipage's control panel doesn't have that much to it) there's the stats and access log, but not a proper error log that I can see, compared to Bitnami wampstack I have been using offline. I tried enabling debugging of the htaccess file but as soon as I add in any lines to htaccess it's the same 500 error which wont help until I get the error log. I'm contacting them now to see if I can get access to it. – Adam First Jun 02 '13 at 23:32
  • I questioned it with them and they showed me an error log, but it only has php code errors like undefined variable, nothing about failed errordocument etc etc. Trying to see if I can add further reporting. – Adam First Jun 03 '13 at 00:09
  • Ok, So I setup error logging in my php.ini file, but no crucial errors like server could not access xxxx, just a single php error for a page id that isn't important and isn't causing problems: [03-Jun-2013 01:08:21 UTC] PHP Notice: Undefined index: p in /hermes/bosoraweb054/b828/ipg.example/index.php on line 70 – Adam First Jun 03 '13 at 01:14
  • @AdamFirst You need to debug it, what I tend to do is to remove partially some code, if it doesn't throw an error then that means that the code I just removed is the culprit. I suspect that if you remove the three lines below `#Remove .php but still allow addressing .php` that it will solve the problem. This is just a guess ... – HamZa Jun 03 '13 at 07:57
  • See previous http://stackoverflow.com/questions/1498966/mod-rewrite-and-get-variables http://stackoverflow.com/questions/8228793/get-variable-after-mod-rewrite http://stackoverflow.com/questions/9229398/htaccess-mod-rewrite-part-of-url-to-get-variable (change [L] to [QSA,L] -- found these with a Google search of "mod_rewrite GET variables") – AlliedEnvy Jun 03 '13 at 14:22

1 Answers1

0

Thanks guys,

My mates and I did end up sorting it, we changed around a few things on the back-end to make the url change from:

http:// www.example.com/article.php?title=Some-Article

to:

http:// www.example.com/article.php?article=Some-Article

then with the following adjustments to the .htaccess file we got it working:

RewriteEngine On
RewriteRule page/([^/]*)/$ /index.php?p=$1 [L]
RewriteRule ^product/([^/]*)$ /article.php?article=$1 [L]
RewriteRule ^([^/]*)/$ /index.php?sort=$1 [L]
RewriteRule ^([^/]*)/page/([^/]*)$ /?sort=$1&p=$2 [L]

so we now have the following urls being formed:

http:// www.example.com/page/2

http:// www.example.com/product/Some-Product/

http:// www.example.com/

http:// www.example.com/category/page/2

The debugging really did help, appreciate it, I turned up the error reporting level in php.ini and made it output to a file which I could access through FTP.

Adam First
  • 435
  • 1
  • 4
  • 19