Allow access to special file in htaccess - web-services

In my .htaccess file I want to allow access to some special php files with query string, for example:
myFile.php?c=1&b=2
I tried many way but did not work. How can I do this?

Related

Htaccess URL rewrite default & pairs in URL

I currently have a URL structure which typically reads
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/ /index.php?app=$1&action=$2&id=$3 [NC,L,QSA]
My issue is, it automatically attempts to include any static files / images etc.
The pattern typically translates to
www.example.com
www.example.com/user/
www.example.com/user/edit/123
and allows for an additional query string to be appended if need be.
Im kinda stuck on how to exclude other media types, is my pattern not written correctly?
thanks in advance

.htaccess redirect - wildcard AND/OR syntax

I updated a website to a new system, and now we have a ton of redirects to handle.
Many of them fall into the same general pattern - old links ending in .html or .php, with certain keywords (product names) in the URL.
Instead of writing an explicit redirect for each case (already up to 1500+, and still growing), I was thinking there's a way to handle them with an AND/OR statement.
For example:
If the OLD URL contains "SKU12345" AND ".html", it should be redirected to /products/SKUGROUP1/SKU12345.
This way, whether the old URL looks like
"/products/oldsubcategory/something/cool-widget-SKU12345.html"
OR
"/something/really-old-version-of-SKU-12345.html"
it should redirect to the same new page.
In other words, I want to catch any links that contain a specific product model/SKU/keyword, AND the extension .html or .php, and redirect them to the new URL (which doesn't have an ending).
I can't just say "if the old URL contains this SKU/keyword", because the new URLs also contain the SKU/keywords, and it would cause a redirect loop. It has to specifically contain .html/.php.
Is this possible to do? If so, can anyone show me the proper syntax?
Thanks!
You can use this redirect rule in root .htaccess to match both cases:
RewriteEngine On
RewriteRule (^|[/-])AA99SKU1-?(\d*)\.(?:html?|php)$ /products/SKUGROUP1/AA99SKU1$2 [L,NC,R=301]
This will match both cases:
"/products/oldsubcategory/something/cool-widget-SKU12345.html"
OR
"/something/really-old-version-of-SKU-12345.html"

.htaccess rewrite rule remove everything after RK=0/RS=

I have a website that is getting a lot of requests for pages that don't exist.
All the requests are based on an existing page, but have RK=0/RS= plus a random string of characters at the end.
For example, the request is:
www.domain.com/folder/article/RK=0/RS=M9j32OWsFAC_u8I6a0xOMjYKU_Q-
but the page www.domain.com/folder/article does exist.
I would like to use htaccess to say:
if RK=0/RS= exists, remove it and everything after
but haven't been able to get it working.
All the htaccess rules talking about removing query strings, but I'm guessing because this doesn't have a ? it's not a query.
Could someone help me understand how to do this?
Someone found where this mess is coming from.
http://xenforo.com/community/threads/server-logs-with-rk-0-rs-2-i-now-know-what-these-are.73853/
It looks like actually NOT malicious, it's something broken with Yahoo rewrites that create URLs that point to pages that don't exist.
The demo described on xenforo does replicate it, and the pattern of the URLS that Yahoo is producing:
http://r.search.yahoo.com/_ylt=A0SO810GVXBTMyYAHoxLBQx./RV=2/RE=1399899526/RO=10/RU=http%3a%2f%2fkidshealth.org%2fkid%2fhtbw%2f/RK=0/RS=y2aW.Onf1Hs6RISRJ9Hye6gXvow-
Sure does look like the RV=, RE=, RU=, RK=, RS= values are of the same family. It's just that somewhere the arg concatenation is screwing up on their side.
You can use this rule in root .htaccess file:
RewriteEngine On
RewriteRule ^(folder/article/)RK=0/RS= /$1 [L,NC,R=301]

htcaccess - Use RewriteRule using slice of {HTTP_REFERER}

I am implementing the translation of a whole PHP site with GETTEXT. I've got a bunch of PHP files (one for each section), and I control the language via a GET variable:
http://www.domain.com/section.php?lang=en [for english]
My first goal is to put this in a nice and clean way, such as:
http://www.domain.com/en/section
I sort of managed to do that (not so nicely) via .htcaccess, but then I come up with two issues:
I'd like every page to identify the language used by taking a look at HTTP_REFERER (is that possible?), so I don't need to rely on SESSION and COOKIES, in case someone has them turned off. I guess the other option would be to echo the current language /en/ in front of every href...
How can I tell htcaccess to rewrite, at the same time:
This:
http://www.domain.com/XX/path/to/whatever/?var1=a&var2=b
To:
http://www.domain.com/path/to/whatever.php?lang=en&var1=a&var2=b
And this:
http://www.domain.com/XX/assets/js/functions.js
To:
http://www.domain.com/assets/js/functions.js?lang=en
Or in other words:
If the path HAS a 2-char folder right after the domain name AND doesn't have an extension, remove the 2-char folder, append a .php to the end of the path, then ?lang=XX, and then the GET variables that came in. Maybe it could first check if it exists as a folder with its own index.php ??
If the path HAS a 2-char folder right after the domain name AND HAS an extension, do the same thing, but keeping the original extension
I know that's a long question to ask, but I'm really lost here...I read a lot about it, but REGEX/htaccess are just too tough for me...I'd appreciate any help
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]{2})/(.*)$ $2?lang=$1 [QSA,L]
For the no extension part I would just put whatever.php in a folder named whatever, and rename the php to index.php. Way easier than with htaccess

htaccess regex question - 301 redirect spaces to dash

I'm just wondering what htaccess mod rewrite regex would be able to redirect any url that contains a space, to the same URL but a dash in replace of the space.
For example
I'd want it to redirect any request going from
mysite.com/test/dl/1/the file name.html
to
mysite.com/test/dl/1/the-file-name.html
Is there any way you can do that?
Yes you can, IF:
1) you hard-code such rule (means, you know the file name in advance):
RewriteRule ^test/dl/1/the\sfile\sname\.html$ /test/dl/1/the-file-name.html [R=301,L]
2) you can use RewriteMap and external rewriting program (Perl/bash/etc script) -- see Apache's manual for details (but I personally do not consider this as a very good option).
Otherwise you will have to do it yourself somehow (inside your own website script, for example).