Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Problem with GoDaddy.com

         

johnngo19

3:07 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



Hi. I am having problem with the .htaccess file. This file is use for search engine friendly url. I am hosting my site with GoDaddy.com, Deluxe hosting plan. The links on my site does not work. Can you help me figure out what is the problem?

RewriteEngine On
RewriteRule ^online/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=file&fileid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?action=browse&cid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/([0-9]+).html index.php?action=browse&cid=$1&page=$3 [L]
RewriteRule ^profile/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=profile&uid=$1 [L]
RewriteRule ^([_A-Za-z0-9-]+).html index.php?action=$1 [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

[edited by: jdMorgan at 4:11 pm (utc) on July 12, 2009]
[edit reason] example.com [/edit]

jdMorgan

4:20 pm on Jul 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only major thing wrong with that code is that the last rule should be the first -- Always put your external redirects first, in order from most-specific pattern (least URLs affected) to least-specific pattern, followed by your internal rewrites, again in order from most-specific to least-specific.

This prevents 'exposing' your script filepaths to clients as URLs, and helps to prevent unexpected rule matches and incorrect rule operation.

A minor problem is that all literal periods in regular-expressions patterns should be escaped by preceding them with backslashes, e.g. "^example\.com"

Neither of these problems would prevent your code from working "at least a little bit."

It is not at all clear what your main trouble is. Did this used to work and now no longer works? Did you change hosts? At a minimum, we need to know:

How did you test -- What URLs did you type?
What results did you expect?
What result did you actually get?
How did the actual results differ from your expected results? (discuss)
Was there any pertinent information on your server error log?

Jim

johnngo19

4:56 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



I changed the code to as shown below but it still doesn't work. Can you edit the code for me please and post it so I can see how it should look like? I used to host with hostgator.com and the code work. But I moved to godaddy.com and now the code doesn't work.

An example of link I tested is http://www.example.com/online/316/Armor-Wars.html. This link is designed to be search engine friendly. The correct address is http://www.example.com/index.php?action=file&fileid=316. I got a page not found when I clicked on http://www.example.com/online/316/Armor-Wars.html. I don't know how to get a server error log.

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example\.com/$1 [R=301,L]
RewriteEngine On
RewriteRule ^online/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=file&fileid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?action=browse&cid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/([0-9]+).html index.php?action=browse&cid=$1&page=$3 [L]
RewriteRule ^profile/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=profile&uid=$1 [L]
RewriteRule ^([_A-Za-z0-9-]+).html index.php?action=$1 [L]

[edited by: tedster at 10:58 pm (utc) on July 12, 2009]
[edit reason] de-link the example [/edit]

jdMorgan

6:56 pm on Jul 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "RewriteEngine on" line must be first. You may need to precede it with
Options +FollowSymLinks -MultiViews

Still two unanswered questions:

> Did this used to work and now no longer works? Did you change hosts?

Contact your host for the location of your error log file, or look around in your site's directories using your FTP client. Using mod_rewrite on a server without having access to the error log file is an almost certain path to misery.

Jim

johnngo19

7:15 pm on Jul 12, 2009 (gmt 0)

10+ Year Member



Yes, this used to work when I host with hostgator.com. Then I changed to godaddy.com and it no longer work. Here is the error log. I don't understand what it mean.

PHP Warning: include(file.html) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/magnizmo/public_html/gamespond/templates/default/main.html on line 119

PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'file.html' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/magnizmo/public_html/gamespond/templates/default/main.html on line 119

I changed the code to this:

RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example\.com/$1 [R=301,L]
RewriteRule ^online/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=file&fileid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?action=browse&cid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9-]+)/([0-9]+).html index.php?action=browse&cid=$1&page=$3 [L]
RewriteRule ^profile/([0-9]+)/([_A-Za-z0-9-]+).html index.php?action=profile&uid=$1 [L]
RewriteRule ^([_A-Za-z0-9-]+).html index.php?action=$1 [L]

[edited by: tedster at 10:57 pm (utc) on July 12, 2009]
[edit reason] switch the example.com in the code [/edit]

jdMorgan

12:46 am on Jul 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Both errors are from PHP, not Apache itself.

It looks like the paths declared in your PHP configuration have not been updated to point to the correct locations for your new server.

You may wish to ask about this in our PHP forum to get more and better answers.

This will make no difference to your immediate problem, but I would suggest the following changes to your code:


Options +FollowSymLinks -MultiViews
RewriteEngine On
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteRule ^online/([0-9]+)/([_A-Za-z0-9\-]+)\.html$ index.php?action=file&fileid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9\-]+)/?$ index.php?action=browse&cid=$1 [L]
RewriteRule ^onlinegames/([0-9]+)/([_A-Za-z0-9\-]+)/([0-9]+)\.html$ index.php?action=browse&cid=$1&page=$3 [L]
RewriteRule ^profile/([0-9]+)/([_A-Za-z0-9\-]+)\.html$ index.php?action=profile&uid=$1 [L]
RewriteRule ^([_A-Za-z0-9\-]+)\.html$ index.php?action=$1 [L]

Note that most changes have only to do with character escaping and pattern anchoring.

Jim