3

Update - Alright thanks everyone for your tests, it really helped. The code is good. My problem was not having absolute "/" links. (Due to moving from public_html folder).

Only 2 concerns i have now.

1.) Replace "^achilles" with "^([0-9a-zA-Z_-]+)" and thumbnails wont appear (parameter data is not being carried???)

2.) How can I make http://funkygames.co/games/achilles/achilles/1 become even shorter like http://funkygames.co/games/achilles Or are the parameters absolutely mandatory.

# Turn Rewrite Engine On
RewriteEngine on     

# Set the base to /games/ so we need not include it in the rules
RewriteBase /games/

#Rewrite for achilles.php?games_path=xxxxxxxxxx.yyy&category_id=zzz
RewriteRule ^achilles/(.*)/([0-9]+) $1.php?games_path=$1.swf&category_id=$2 [NC,L]

Where i learned: www.youtube.com/watch?v=1pbAV6AU99I


SOLVED! Thanks to you guys. Solution:

# Turn Rewrite Engine On
RewriteEngine on     

# Set the base to /games/ so we need not include it in the rules
RewriteBase /games/

#Rewrite for achilles.php?games_path=xxxxxxxxxx.yyy&category_id=zzz
RewriteRule ^([0-9a-zA-Z_-]+)/([0-9]+) $1.php?games_path=$1.swf&category_id=$2 [NC,L]

http://funkygames.co/games/achilles/1

7
  • A problem you have with your site is that you are using relative URLs to images, CSS and JS. When you change the URL structure you are changing what these resources/URLs are relative to and so they cannot be found. So, even if your internal rewrite "works", your site is still going to break. See this answer for more information: webmasters.stackexchange.com/a/86458/1243
    – MrWhite
    Jan 19, 2016 at 13:15
  • Thank you. This was the main problem. Not having "/" infront of directories. I now have: "funkygames.co/games/achilles/achilles/1" Is there anyway I can make it "funkygames.co/games/achilles" or is it a MUST that I include these parameters? I tried to replace achilles.php with something dynamic like ([0-9a-zA-Z_-]+) but for some reason it wouldnt carry the "category_id" information unless i went static.
    – Hulio-G
    Jan 19, 2016 at 15:30
  • #Rewrite for achilles.php?games_path=xxxxxxxxxx.yyy&category_id=zzz RewriteRule ^achilles/(.*)/([0-9]+) $1.php?games_path=$1.swf&category_id=$2 [NC,L]`
    – Hulio-G
    Jan 19, 2016 at 15:30
  • Any parameters you need in the rewritten URL must be present in the original URL - so it depends on what your application expects. In your question you have /games/achilles/1 - this looks doable, however, in your comment you are missing what would be the category_id - presumably you do need the category ID, or can it be omitted?
    – MrWhite
    Jan 19, 2016 at 17:02
  • Id rather have "games/achilles/1" But it appears that I need "games/achilles/achilles/1" due to the name of the .swf file. I dont mind keeping that category id. But if i could simplify this to just "games/game-title/category-id" rather than "games/game-title/game-title.swf/category-id" that would be perfect.
    – Hulio-G
    Jan 19, 2016 at 17:06

2 Answers 2

3

SOLVED! Thanks to you guys. Solution:

# Turn Rewrite Engine On
RewriteEngine on     

# Set the base to /games/ so we need not include it in the rules
RewriteBase /games/

#Rewrite for achilles.php?games_path=xxxxxxxxxx.yyy&category_id=zzz
RewriteRule ^([0-9a-zA-Z_-]+)/([0-9]+) $1.php?games_path=$1.swf&category_id=$2 [NC,L]

http://funkygames.co/games/achilles/1

If your website is appearing but its not showing pictures or dynamic database content. Then you must make sure you use absolute links

"/this-is-absolute"(will work from any folder) "this-relative"(will only work from public_html)

0
2

I have: http://funkygames.co/games/achilles.php?games_path=achilles.swf&category_id=1

I want: http://funkygames.co/games/achilles/achilles/1 or even better: funkygames.co/games/achilles/1 (if that's possible)

Try this:

RewriteRule ^games/achilles/(.*)/([0-9]+)$ /games/achilles.php?games_path=$1.swf&category_id=$2 [NC,L]

And if the game name needs to be case sensitive, remove the NC from [NC,L].

1
  • If this .htaccess file is in the /games directory then you'll need to remove games/ from the start of the RewriteRule pattern. (Optional: You could also remove the /games/ prefix from the substitution.)
    – MrWhite
    Jan 19, 2016 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.