I need some help with doing a RewriteBase for .htaccess - .htaccess

I recently got an arcade script through a membership site that I belong to. The owner of the site offered free install of the script. I registered a domain name and got a hosting account with godaddy.com The script was installed, but I am having a slight problem. Everything else seems to be working fine, except for clicking on the links on the left hand menu that says "Categories".
Here is my site: http://www.freeonlinegamerooms.com
I called GoDaddy customer service and was advised that I needed to add a Rewrite Base to my .htaccess file . They sent me a link to the apache site, but it hasn't helped me at all, as I am a non-technical person. It's all Greek to me. The guy who installed my script has tried to get it fixed, to no avail. He said he isn't a progammer either. Here is the text of my .htaccess file, as it presently exists:
Options +FollowSymLinks
RewriteEngine on
RewriteRule "^game/([0-9]+)/$" file.php?id=$1 [Last]
RewriteRule "^category/([0-9]+)/([0-9]+)/$" category.php?id=$1&page=$2 [Last]
Can anyone help me with this, please? All I want is a site that works properly. I am sure this something very easy for a programmer to figure out, I'm just at a loss myself because I'm not a programmer.
Thanks in advance for any help/advice
Doug

I think you need to put a slash in the rewrite rule after the ^.
Options +FollowSymLinks
RewriteEngine on
RewriteRule "^/game/([0-9]+)/$" file.php?id=$1 [Last]
RewriteRule "^/category/([0-9]+)/([0-9]+)/$" category.php?id=$1&page=$2 [Last]
edit: this is wrong, see my follow-up comment in this answer.

Related

.htacces redirect from domain 1 to domain 2 subdir, keeping path

I have found plenty of useful answers in this forum that got me to the point I'm at, however the configuration of my .htaccess redirect is still not 100% perfect.
Set-up
I have two domains registered:
domain1.is (only domain)
domain2.me (domain + hosting)
The domain1 redirects as wildcard everything to domain2.
What I'm trying to do
I have installed yourls (url shortened) on domain2.me/yourls and want to redirect all domain1.is/randomstring to domain2.me/yourls/randomstring.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.is$
RewriteRule (.*) https://domain2.me/yourls/$1 [R=301,L]
RewriteRule ^$ store [L,R=301]
The issue
So far I got that domain1.is/randomstring goes to domain2.me/randomstring, however the subdirectory in the .htacess file seems to be completely ignored, effectively rendering the whole system unusable.
I've tried adding a condition, changing the subdirectory, etc. but can't seem to find the reason why. Can anyone help please?
Thanks in advance and cheers from Berlin!
I'll share my solution in case someone else stumbles upon this conversation. The details/history are in the comments of the question.
TLDR;
Just set up a wildcard redirect to the subdirectory.
(not sure if the first redirect is useful, but still).
Important point: you don't even need to touch the .htaccess file (in my particular case yourls already had one, so I left it as it is).
Credit: thanks #CBroe for pointing me in the right direction.

htaccess from old forum url to new one

until now I have always used htaccess to rewrite URLS in order to have non-SEF url to SEF urls.
Today I am facing a new challenge that honestly, beeing non confident in regular expression, I really don't know how to achieve.
I have a situation where a forum on a website of mine has been update in the following form:
previous link: www.domain.com/forum3/topic/name-of-topic/post/7548
new link: forum.domain.com/Topic-name-of-topic/
How do I intercept /post/37764 string and tell htaccess to not consider it?
And how to instruct the server to build that kind of url instead of the provious. I am very confused about it.
Any suggestion? Thank you very much. Is there any resource that I can read to help me better understand the case?
Thanks again.
EDIT
Florian answer is correct. I just added few mods to fit it better.
RewriteEngine On
#RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
RewriteRule ^forum3/topic/([^/]+)-[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
You can try this code :
RewriteEngine On
RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ /Topic-$1/ [L,R=301]
/([^/]+)/ means that we want to catch a string containing one or more characters except / preceded and followed by a /.
This link might help you to test your .htaccess files :
Test your apache htaccess files online

The requested URL /public_html/ was not found on this server

I'm working on a local MAMP website. I use a micro MVC framework to use friendly urls
so I don't need to call index.php (which is inside of public_html directory) in the urls.
To achieve that, I have the following htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Then I have the following line in /etc/hosts
127.0.0.1 mywebsite
Also, I have the following in httpd.conf
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/mywebsite"
ServerName mywebsite
</VirtualHost>
So if I simply call http://mywebsite from the browser, the whole thing works smoothly.
So what's the problem?
The problem appears if I try to reach the same page from another machine in my LAN.
So if I write http://192.168.1.15/mywebsite the answer is:
Not Found
The requested URL /public_html/ was not found on this server.
I get the same message if I call http://localhost/mywebsite from my own machine.
I have the feeling that is something related to .htaccess, but I've been trying a
lot of different ideas I've found in the web, and nothing works.
I'd like to fix this, because I need other people to check the website from their machines.
If you have any clue please help. Thanks a lot.
Edit: I can't solve this, so as a temporary fix I've created a free account at AppFog for my team to be able to access the page until we go to production.
After all these years, I thought that computing would be easier... it's getting harder, actually. The htaccess file is a huge mistery to me! Thanks anyway :)
By the way... as I told you, I've found a way to fix the problem. The funny thing is I have to use a different .htaccess file. I thought you could be interested, provided that it seems you like computing stuff :)
This is the .htaccess that works in my LAN debian server:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(www/.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
As you can see, it's different from the one I showed you at my first post. My conclusion? Well, even when I always try to keep things simple, life shows me one and another time that everything can be more complicated. Look at the .htaccess file. It's so funny... I've learnt to work with it by using different combinations of code.
Isn't it crazy? Yes it is. Please let's do understandable software. Thank you!
Ok, I've been trying a lot of different things and all of them fail. The only solution I've found is to install the web site in a separated LAN debian server. Everything works ok in that way, but it's not possible to make it work from my machine with MAMP.
Why not? Well, I don't know. After a lot of years in computing, I've learnt to say "I donĀ“t know", you know what I mean.
I've been working for a few days with an AppFog account for free but, you know, that thing cannot work when you put a database and the whole thing there. Obvious.
So at the end the only solution I've found has been to put everything at that local LAN debian server.
Thank you anyway :)

How to perform htaccess rewrite

Here is the summary of my problem.
I have created a Facebook like button. It works correctly most of the time, however not when following the link from somebody's actual "like" post. It seems that Facebook is adding some more info to the URL. For instance, I have
www.example.com/blog.php/6
but Facebook adds
www.example.com/blog.php/6?fb_action_ids=10201090685057512&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582
When a user follows this link they get a Mysql syntax error. If they follow the first link there is no problem. I thought I could just strip off all that extra text from the URL.
I created a .htaccess file and placed it in my root directory on GoDaddy.
I Tried several different rewrites.
Nothing has worked. This is the latest thought I tried:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*&)?fb_action_ids=
RewriteRule ^(.*)$ $1?%1 [R=301]
Do I need to change my .htaccess file or is there another way to solve this problem?
Thanks for the help.

URL Rewrite best practice & how to set it up with htaccess

I have a small personal project I'm working on, and before I get too deep into it, I'd like to get some opinions here on the best practices regarding the set up and URL scheme... and how I might set up the .htaccess rewrites for the following. My questions are:
Is the below set up the best way to manage user information in a small user profile setup?
I have worked out how to get the subdomain working for the rewrite username.domain.com with wildcard subdomains and httpd.conf file set up... but I am stuck on the rest of the scheme seen below. Basically, a user profile will always result in username.domain.com and then appended with the various pages within their account (photos, videos, notes etc). How would I set up the .htaccess rewrites to accommodate this? I really appreciate any advice here. I have done a ton of research here on stackoverflow, and on other sites, but I can't find a decent explanation to achieve this.
Thanks for any help.
www.domain.com/profile.php?u=username --> username.domain.com
www.domain.com/photos.php?u=username --> username.domain.com/photos
www.domain.com/photos.php?u=username&a=album --> username.domain.com/photos/album
www.domain.com/photos.php?u=username&a=album1&p=photoid --> username.domain.com/photos/album1/photoid
www.domain.com/settings.php?u=username --> username.domain.com/settings
etc
Your proposed setup looks fine to me. Here are some rules for .htaccess (make sure you have mod_rewrite enabled and AllowOverride All set in your httpd.conf):
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule ^$ http://www.domain.com/profile.php?u=%1 [L,QSA]
RewriteRule ^photos/?$ http://www.domain.com/photos.php?u=%1
RewriteRule ^photos/([^/]+)/?$ http://www.domain.com/photos.php?u=%1&a=$1
RewriteRule ^photos/([^/]+)/([^/]+)/?$ http://www.domain.com/photos.php?u=%1&a=$1&p=$2
RewriteRule ^settings/?$ http://www.domain.com/settings.php?u=%1
Wich server do you use? And first of all use rewrites in the config file of your server, not htaccess, htaccess slows the server down.
Edit: Iam not shure about the speed, but as far as i remember htaccess slows down apache, i dont know about how much. Iam sry you have to google that :)

Resources