Forum Moderators: phranque
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]
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
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]
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
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]
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]
Jim