.htaccess image to php redirect rewrite - .htaccess

I have a site that gives you a random cat gif every time you refresh, and it works in image tags. Some forums won't let you put http://randomcat.tk in an image tag, so I was thinking I could use RewriteEngine so people can put http://randomcat.tk/cats.gif and have it redirect to index.php.
Sorry if that made no sense.

Should work:
RewriteRule ^cats.gif$ index.php [L]

Try this:
RewriteRule ^.+$ /index.php [L]
this will redirect any request to index.php

Related

What is wrong htaccess

I have the following htaccess rules but I dont know how to make it work:
RewriteEngine on
RewriteRule ^game/([^/]*)$ index.php?cash=$1
The following is the screen shot of my folders structure:
Can someone tell me how to get it to work? I have also tried:
RewriteRule ^index.php([^/]*)$ index.php?cash=$1
The URL that I want to display is: http://localhost/biteep/game/100 while the URL that I want the browser to go to is http://localhost/biteep/game?cash=100
Try to put a rewrite base into your .htaccess:
RewriteBase /biteep/
And this route should be enough:
RewriteRule ^game\/(\d+)$ index.php?cash=$1
So it works when I do this
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?cash=$1

HTACCESS moving pages and masking

I have the current domains
http://domain.com/dev/programme and http://domain.com/dev/software
But I want to point them to http://domain.com/dev/programmes http://domain.com/dev/softwares
I have set up the following htaccess
Redirect 301 /new/programme http://www.domain.com/new/programmes/
Redirect 301 /new/software http://www.domain.com/new/softwares/
This works but the problem comes when you try access sub pages of the main links. The sub pages rely on the slug in the url.
eg. http://domain.com/dev/programme/page and whenever I try access this page with htaccess set like the above it sends me on a redirect loop.
How would I be able to keep the link like http://domain.com/dev/programme/page but have it http://domain.com/dev/programmes whenever its accessed?
Try this:
RewriteEngine On
RewriteRule ^dev/programme$ dev/programmes [L]
RewriteRule ^dev/software$ dev/softwares [L]
RewriteRule ^dev/programme/(.*)$ dev/programmes/$1 [L]
RewriteRule ^dev/software/(.*)$ dev/softwares/$1 [L]
You can do this in a single rewrite rule:
RewriteEngine On
RewriteRule ^(dev/programme|software)(/.*)?$ /$1s$2 [L,NC]

.htaccess url rewrite rule to subdirectory not working

I want this: RewriteRule ^paper$ /express/index.php?c=p [L] but it does not work. Instead, it's trying to send me to /index.php?c=p, ignoring the subdirectory express altogether. However, RewriteRule ^express/paper$ /express/index.php?c=p [L] works. This is my .htaccess code:
RewriteEngine on
RewriteBase /
RewriteRule ^paper$ /express/index.php?c=p [L]
RewriteRule ^express/paper$ /express/index.php?c=p [L]
The url I WANT is just http://site.com/paper but I have to do http://site.com/express/paper to get the rewrite rule to work.
And yes, I only use one of those rewrite rules at a time.
UPDATE
Well, I'm not really getting any responses, so I'm going to go ahead and close this browser tab. I'll check back now and then but don't be offended if it takes a little while. Thanks for any help offered.

Rewrite URL and permanently redirect to new URL

I've just spent the last 2 hours trawling through Google and the Stackoverflow archives to see if I could find an answer to my question and instead of finding nothing, I've found too much! So unfortunately I'm having to add to the mountain of 301 redirect questions. Sorry. And thanks for taking a look at this one ;)
Basically, I've got a blog for which I'm looking to simplify the URL. Currently the URLs look like this:
http://tempertemper.net/post.php?s=2012-05-30-freeagent
I'd like them to look like this:
http://tempertemper.net/2012-05-30-freeagent
I've tried adding RewriteRule /(.*)$ /post.php?s=$1 to my .htaccess file but it's not having it.
The full file currently looks like this:
<ifModule mod_rewrite.c>
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.tempertemper\.net$
RewriteCond %{REQUEST_URI} !cron.php
RewriteRule ^(.*)$ http://tempertemper.net/$1 [R=301,L]
</ifModule>
I've tried adding this after the canonicalisation bit that redirects www. to non www.:
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?s=$1
It sort of works. I can then link to http://tempertemper.net/2012-05-30-freeagent but the problem is, http://tempertemper.net/post.php?s=2012-05-30-freeagent still exists. This is more than likely bad for seo as I guess I'll have duplicate content, in the eyes of the search engines. I've tried putting a [R=301] on the end of the new line but it stops the new link working. Also tried putting the ,L in the square brackets and removing it from the canonicalisation command, but no joy (L is for last command, isn't it…?).
Basically, I'm after all URLs that generate or have generated with post.php?s= in them to permanently redirect to the ones without post.php?s= so that any links that come in to those pages already are redirected and any links in the future will direct straight to the new-look URL.
Hope that makes sense…
Thanks,
Martin :)
Apache actually fixes local paths => proper fully qualified names (my original assumption), but I see that your file actualy checks for the wrong files. Using your supplied file I think this will work as the file contents:
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
# don't redirect post.php to itself
RewriteCond %{REQUEST_URI} !post.php
# don't redirect error.php to post.php
RewriteCond %{REQUEST_URI} !error.php
RewriteRule ^(.*)$ "/post.php?$1" [R=301,L]

modrewrite website with slash in .htaccess

How can I translate an URL like:
http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
to:
http://localhost/mySite/OFFERS/ARTICLE/DETAIL
if one parameter is empty it should still work like this:
localhost/mySite/?link=OFFERS&sublink=ARTICLE
localhost/mySite/OFFERS/ARTICLE
Extra problem: There is an enter page under index.php and the rewrite should work with index2.php. Best would be if it would work under localhost and on live system without changes.
Currently I'm using: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L]
But that only works for one parameter and I couldn't improve this code for ages ^^
RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]
Note that localhost/mySite/OFFERS/ARTICLE links to localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink= and not localhost/mySite/?link=OFFERS&sublink=ARTICLE.
Should not be a big issue, but make sure the PHP code doesn't us isset($_GET['subsublink']).
Try adding the following to your htaccess file in the mysitedirectory of your site.
RewriteEngine on
RewriteBase /mysite/
# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]
#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]

Resources