jeudi 30 avril 2015

Loading a controller on a subdomain using mod_rewrite

I'm trying to load a controller from my MVC on a subdomain. So for example, I want to load the contents of /affiliates/something on test.domain.com thus http://ift.tt/1GIbpsR

Options +FollowSymLinks
Options +Indexes
RewriteEngine On 

RewriteBase /

RewriteCond %{HTTP_HOST} !^solvex
RewriteCond %{HTTP_HOST} ([^.]+)\.solvex 
RewriteRule ^(.*)$ /affiliates/agents_sites/?subdomain=%1 [L]

RewriteCond %{REQUEST_FILENAME} !(/web/)
RewriteCond %{REQUEST_FILENAME} !(/html/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* web/bootstrap.php [QSA,L]

However, on the following line:

RewriteRule ^(.*)$ /affiliates/agents_sites/?subdomain=%1 [L]

When I remove the [L] flag it does not work but with the [L] flag it runs into an Internal Server Error.

htaccess language redirect loop chrome

Hey guys I am new to the .htaccess stuff and I am encountering a problem.
My goal is to have every Dutch and Belgium user redirected to bloggerlist.nl and the remaining should be redirected to bloggerlist.co.

I tried some other threads but it didn't work for me, so here's my htaccess for bloggerlist.nl:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} !^bloggerlist.co [NC]
RewriteCond %{HTTP:Accept-Language} (en) [NC]
RewriteRule ^(?!en/) http://ift.tt/1GIbpcu [R,L]

</IfModule>

# END WordPress

And the bloggerlist.co htacces is the same except for the three lines:

RewriteCond %{HTTP_HOST} !^bloggerlist.nl [NC]
RewriteCond %{HTTP:Accept-Language} (nl) [NC]
RewriteRule ^(?!nl/) http://ift.tt/1GIbpcy [R,L]    

So this works in safari etc. but not in chrome. I think this is due to chrome having multiple supported languages in the browser ( English and Dutch) and the htaccess detects those languages and then it keeps redirecting them. With safari the browser language is on Dutch only, so this works as desired.

So I had the idea to don't redirect anymore if the HTTP_HOSTS is already from bloggerlist.nl or bloggerlist.co.

I didn't implement the Belgium language yet. Thanks in advance.

Redirect any GET request to a single php script

After many hours messing with .htaccess I've arrived to the conclusion of sending any request to a single PHP script that would handle:

  • Generation of html (whatever the way, includes or dynamic)
  • 301 Redirections with a lot more flexibility in the logic (for a dumb .htaccess-eer)
  • 404 errors finally if the request makes no sense.

leaving in .htaccess the minimal functionality.

After some tests it seems quite feasible and from my point of view more preferable. So much that I wonder what's wrong or can go wrong with this approach?

  • Server performance?
  • In terms of SEO I don't see any issue as the procedure would be "transparent" to the bots.

The redirector.php would expect a query string consisting on the actual request. What would be the .htaccess code to send everything there?

Grocery CRUD 1.5.1 on CodeIgniter 3 - htaccess issue

I'm trying to learn a little abou Grocery CRUD and run into this strange situation.

I've performed a clean installation of Codeigniter3. I've configured my a virtual-host like this:

<VirtualHost *:80>
    ServerAdmin admin@codeigniter.grocery
    DocumentRoot "E:/xampp/htdocs/codeigniterGrocery"
    ServerName codeigniter.grocery
    ErrorLog "logs/codeigniter.grocery-error.log"
    CustomLog "logs/codeigniter.grocery-access.log" common
</VirtualHost>

And added a line to my file hosts, under windows.

Then I setup this htaccess after some research:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Remove the "index.php" part of URI
    # Remove access to "codeigniter" and "data" folders
    RewriteCond %{REQUEST_URI} ^(codeigniter|data).*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    # Block access to "hidden" directories whose names begin with
    # a period. e.g. .git, .svn
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the root index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

Changed the config.php file's lines to:

 $config['index_page'] = '';
 $config['uri_protocol']    = 'REQUEST_URI';

Now, calling for:

  • codeigniter.grocery/welcome
  • codeigniter.grocery/index.php/welcome

Produce the same result which is the welcome page of codeigniter.

I assume that the htaccess is working then.

However if I go for codeigniter.grocery/examples I get a "service unavailable" error. If I restore the configuration to allow the use of index.php in the URL everything works fine.

I've tried changing the $config['uri_protocol'] into 'AUTO', changing the htaccess following some hints around the web but without success.

Different rewrites for several different domains in htaccess

I'm trying to find a way make rewrite rules not to interfere with each other.

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
RewriteRule ^old-url.html(.*)$ /new-url-1/? [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule ^old-url.html(.*)$ /new-url-2/? [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com
RewriteRule ^old-url.html(.*)$ /new-url-3/? [R=301,NC,L]

RewriteCond %{HTTP_HOST} ^(www\.)?domain4\.com
RewriteRule ^old-url.html(.*)$ /new-url-4/? [R=301,NC,L]

If I access, let's say http://ift.tt/1AjMebo I'm redirected to http://ift.tt/1ETUPsH

Any ideas? Thanks,

htaccess accept language from the browser and redirect

I have some questions to accept languages and htaccess. I have a multilanguage homepage. In the root directory are only the robots.txt, .htaccess, sitmaps and the directories for the languages de for german and en for english. What I do need is that the browser indenified the right language. If are not the languages german or english, then choose english as the default language.

The problem is that the forwarding does not work correct. I type http://example.com than I am redirected to http://ift.tt/1EtjfWz wihtout any css styles. When I click on a link than I am redirected to hxxx://www.webpack.de/de/anysite.php

My domain is not there. What is wrong? Please take a look to my .htaccess.

Thank you for your help. Sorrry I can't post more than 2 links.

Jklein

/root
|-index.php
|-de
|-en
|-robots.txt
|-sitemap.xml
|sitemap-de.xml
|sitemap-en.xml

.htaccess

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{REMOTE_ADDR} !^10\.30\.7\.1(?:37|38|39|40)$
RewriteRule ^ http://ift.tt/1BzhSUh} [R=301,L]

RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ http://example.com/en/ [L,R=301]

RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ http://example.com/de/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

# for all other languages use English
RewriteRule ^$ http://example.com/en/ [L,R=301]

RewriteRule ^(en|de)/?$ index.php?lang=$1 [QSA,NC,L]

Unable to commit .htaccess file with subversion with ubuntu client

I can't commit an .htaccess file to a subversion server, using http protocol. Some tips about this issue:

  • We can import this file when we are creating repository, but we can't commit changes to it.
  • We can commit changes with a Tortoise client on a windows machine.
  • We are not able to commit changes using command-line subversion client, on a ubuntu machine.

I made some googling and also looked the suggestions provided here at stackoverflow, without sucess for now.

I have changed this apache directive:

<Files ~ "^\.ht">
     Order allow,deny
     Deny from all
</Files>

To:

<Files ~ "^\.ht">
    Order allow,deny
    Allow from all
</Files>

But no success. Also I have change the AllowOverride directive to all, without success too.

Any suggestions are welcome,

Thank you very much.

AngularJS delay loading data from MySQL database

I'm using angular in a simple application like:

app.js

app = angular.module('app', []);
app.controller("NavCtrl",function($scope,$http){
    var serviceBase = 'v1/';
    $http.get(serviceBase + 'orderoverview/58').then(function (results) {
        $scope.categories = results.data;
        $scope.getTotal = function(){
    var total = 0;
    for(var i = 0; i < $scope.categories.length; i++){
        var categories = $scope.categories[i];
        total += (categories.productPrice * categories.orderdetailAantal);
        if(categories.extra1 != "")
        {
          total += categories.extrasPrice;
        }
    }
    return total;
}
    });
});

HTML

<!DOCTYPE html>
<html lang="en" ng-app="app">
  <head>
    <meta charset="utf-8">
    <title>Served</title>
  </head>
  <body ng-cloak="">

<div class="navbar navbar-default megamenu">
  <div class="container" ng-controller="NavCtrl">
      <ul class="nav navbar-nav">
        <li ng-repeat= "p in categories">{{p.orderdetailAantal}} x {{p.productTitle}} {{p.productPrice}} <br> {{p.extra1}} {{p.extra2}} {{p.extra3}} {{p.extra4}} {{p.extrasPrice}}</li>
      </ul>
      <p>Total: {{ getTotal() }} euro</p>
</div>
</div>

    <script src="libs/angular.js"></script>
    <script src="app/app.js"></script>
  </body>
</html>

And this works but every time I load the page there is a delay of almost 3 seconds to get the data from the db and show it in my html page... When I surf directly to the API, I built using PHP, the required data is shown instantly...

How is this possible and how can I speed up this proces?

(if needed, my API and .htaccess)

API

require '.././libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app = \Slim\Slim::getInstance();

$app->get('/orderoverview/:customerID', function ($customerID) {

$sql = "SELECT `customerName` FROM `customers` WHERE `customerID` = $customerID";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $customername = $row["customerName"];
    }
} 
else {
    echo "Customer name failure";
}

$sql = "SELECT `orderID` FROM `order` WHERE `customerID` = $customerID";
$result = $conn->query($sql);
if($result->num_rows > 1){
    echo "You already have a pending order! <br>";
}
else if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $orderID = $row["orderID"];
    }
    step2($orderID, $customername);
} else {
    echo "GET orderID failure";
}
});
$app->run();

function step2($orderID, $customername){

mysql_connect($servername, $username, $password);
mysql_select_db($dbname);
$query = mysql_query("SELECT `orderdetailID` FROM `orderdetail` WHERE `orderID` = '$orderID'");
$results = array();
while($line = mysql_fetch_array($query, MYSQL_ASSOC)){
    $results[] = $line;
}
step3($orderID, $results, $customername);
}

function step3($orderID, $results, $customername){
global $conn, $servername, $username, $password, $dbname;

$to = 0;
$extracounter = 1;
$extrasprice = 0;

foreach($results as $key=>$odt)
{
    $extracounter = 1;

    $odb = $odt["orderdetailID"];
    $sql = "SELECT `productID`, `orderdetailAantal` FROM `orderdetail` WHERE `orderdetailID` = '$odb'";
    $sql2 = "SELECT `extraID` FROM `orderdetailextra` WHERE `orderdetailID` = '$odb'";

    $result = $conn->query($sql);
    $result2 = $conn->query($sql2);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $sql3 = "SELECT `productTitle` FROM `products` WHERE `productID` = '$row[productID]'";
            $sql4 = "SELECT `productPrijs` FROM `products` WHERE `productID` = '$row[productID]'";

            $result3 = $conn->query($sql3);
            if($result3->num_rows > 0) {
                while($row1 = $result3->fetch_assoc()){
                    $productTitle = $row1["productTitle"];
                }
            } 

            $result4 = $conn->query($sql4);
            if($result4->num_rows > 0) {
                while($row1 = $result4->fetch_assoc()){
                    $productPrice = $row1["productPrijs"];
                }
            } 

            $order[$to] = array(
                "orderdetailID" => $odb,
                "productTitle" => $productTitle,
                "productPrice" => $productPrice,                
                "orderdetailAantal" => $row["orderdetailAantal"],
                "extra1" => "",
                "extra2" => "",
                "extra3" => "",
                "extra4" => "",
                "extrasPrice" => ""
            );
            $to++;
        }
    } else {
        echo 'fout sql 1';
    }                

            }
        }

    }

}
    echoResponse(200, $order);

}
function echoResponse($status_code, $response) {
    global $app;
    $app->status($status_code);
    $app->contentType('application/json');
    echo json_encode($response,JSON_NUMERIC_CHECK);
}

.HTACCESS

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
RewriteBase /localsites/serf/weap/api/v1

How to deny access to a directory without restricting it local?

So, I'm currently repairing an old project. Yes, It's old, ugly and unsafe, but i don't get paid to rewrite the entire thing, only to add a new function. Unfortunately, i came across a file called settings.ini and saw this:

;database
resources.db.adapter = "mysqli"
resources.db.param.host = "xxxxxxxxxx"
resources.db.param.username = "xxxxxxxxxxx"
resources.db.param.password = "xxxxxxxxxxx"
resources.db.param.dbname = "xxxxxxxxxxx"
resources.db.isDefaultTableAdapter = true

So, I tried to access them via web browser, and since it's a usual .txt file, if I know the address, I can access it from anywhere I want. I guess i don't have to mention that this is a huge risk for them. Personally, i could say that i don't care or didn't see this, but to be honest, i feel bad doing it. The problem is, I don't have access to the server where this tool is running, so i can't use the firewall to block access from outside.

My first apporach was via .htaccess, which contained the following code:

<Directory "configs">
Satisfy Any
Order Require,Allow,Deny
Require local
Deny from all
</Directory>    

The files are in the folder configs, this is a simplified file structure:

app
|-- folder1
|-- folder2
|-- folder3
|-- configs
|-- .htaccess

Unfortunately, that didn't work, I still can access the file via any browser. Is there a chance to achieve this via a .htaccess file?

.htaccess redirecting only pages with no subfolder

I am using .htaccess to redirect pages from an old website to a new site. The URL structure has changed completely, but thanks to a SEO person I have a complete list of URLs I have to redirect and take care of.

My .htaccess looks like the following:

Options +FollowSymlinks
RewriteEngine On
Redirect 301 /some-guy http://ift.tt/1GHXWkX
Redirect 301 /some-other-guy http://ift.tt/1GHXWkX
...
Redirect 301 /de/some-page http://ift.tt/1GHXUcH
Redirect 301 /de/another/page http://ift.tt/1GHXWl3

Of course the URLs can be even longer and contain query strings and stuff like that. The new website has a different URL structure and does not need query strings and nothing.

Now, while the first two redirects work perfectly, every redirect which contains a subfolder fails to redirect to the target location. The last URL for example redirects to

http://ift.tt/1JCzBk5

What am I missing here?

Htaccess mobile redirect two subdomains

can anyone please help

I have a website www.example.com which redirects to www.m.example.com

This works perfectly with the following htaccess code

# Check if this is the m=no query string


RewriteCond %{QUERY_STRING} (^|&)m=no(&|$)
 # Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]
 # Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
 RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
    RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
    RewriteCond %{HTTP:Profile}       !^$
# Check if we're not already on the mobile site
 RewriteCond %{HTTP_HOST} !^m\.
 # Can not read and write cookie in same request, must duplicate condition
 RewriteCond %{QUERY_STRING} !(^|&)m=no(&|$) 
 # Check to make sure we haven't set the cookie before
 RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
 # Now redirect to the mobile site
RewriteCond %{REQUEST_URI} !\.(?:gif|jpe?g|png)$ [NC] 
RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]

However my problem is I also have the subdomain ru.example.com which is now being redirected to the mobile subdomain m.. I do not want this subdomain ru to be redirected to the mobile version.

I want the desktop site www.example.com to be redirected to www.m.example.com

I want the desktop site www.ru.example.com to be redirected to www.mob.example.com

Please help thanks

mercredi 29 avril 2015

From where I should learn about htaccess

I'm working in PHP but didn't know about htaccess. And these days I know how much the value of htaccess. So, I decide to learn first htacces then step forward. But don't know from where I should start? Please provide your guidelines. I want to learn complete tips & tricks about htaccess. I know something but I want to learn more techniques. Like I want to create SEO friendly url and other category url's. Thanks in advance.

I want to redirect 15000 pages of my website

I have a social networking website, i want to redirect about 15000 previous web pages. I have been suggested by other experts to use 301 redirect. All i want to know is that how redirection will not effect search engine ranking, is there any better way to move all the pages without any harm?

Need to write multiplae htaccess rule with multiple parameters

I've some rules already written in htaccess to convert .php extension to HTML and they are working fine but now I need to write rule for different page with same parameter but it if I set same rule for different page its not working its redirecting on same page.

Below is my htaccess file code

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/

# add everything for webservice/...
RewriteRule ^webservice(/.*)?$ - [L,NC]

#redirect localhost/apnaujjain/blog.php?page_id=1&post_id=1&action=blog to localhost/apnaujjain/1/1/blog.html

#RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
#RewriteRule . %1/%2/%3.html? [R=301,L]
#RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ blog.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]

#redirect localhost/apnaujjain/page.php?page_id=1&album_id=1&action=contacts to localhost/apnaujjain/1/1/contacts.html

RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&album_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2/%3.html? [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/([^./]+)\.html$ page.php?page_id=$1&album_id=$2&action=$3 [NC,L,QSA]

#redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to localhost/apnaujjain/1/contacts.html

RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+)\s [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^./]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]

#redirect localhost/apnaujjain/contacts.php to localhost/apnaujjain/contacts.html

RewriteCond %{THE_REQUEST} \s/+(.+?)\.php\s [NC]
#RewriteRule ^(admin|webservice)($|/) - [L]
RewriteRule !^admin/ /%1.html [NC,R=302,L,NE]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]

I have already written comment on every rule for what its doing. Now currently all rules are working but when I added other rule it stopped working so I just commented that rule.

Rule for page.php is working but when I change page to blog.php some rules work but some rule with multiple parameter with blog.php doesn't work.

Any help is really appreciated

$routeParams Hard Refresh not working on server in angular js

Here is my .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

Here is app.js

var app = angular.module('router', ['ngRoute']);

app.controller('main', function($scope, $location, $routeParams){
    $scope.test = 'testing';
    $scope.theID = $routeParams.theID;
});

// Routing Configuration
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/about', {
            templateUrl: 'views/about.html'
        })
        .when('/paramtest/:theID', {
            templateUrl: 'views/aboutID.html',
            controller: 'main'
        })
        .otherwise({
            templateUrl: 'views/home.html'
        });

        $locationProvider.html5Mode(true);
}]);

Here is aboutID.html

ID: {{theID}}

When I go to http://domain.com/about it works great, even if I do a cmd+r refresh it still loads the page fine.

If I click on a link from within the app and go to http://ift.tt/1Ert1bD it works fine.

The problem is if I try going directly to http://ift.tt/1Ert1bD or doing a hard refresh http://ift.tt/1Ert1bD angular routing no longer works and all of the variables are outputted like this {{var}}

Wordpress rewrite table plugin

I'm looking for a solution to rewrite URL in Wordpress site, in such way to keep it compatible with the previous website.

So, with the following code:

function custom_rewrite_basic() {
  add_rewrite_rule('^whatever/([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_basic');

... Wordpress will redirect /whatever/123 to index.page?page_id=123, but what I want is not an redirect, but to keep whatever/123 in URL. In this case, redirection works and URL became permalink from Permalink Common Settings, which is not desirable solution.

remove and disallow extensions with .htaccess

I found this script or removing extensions from php files:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

While this works, it still allows files to be accessed if you type them in with their extension, which I don't want.

I tried the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([.]+)$ $1.php [NC,L]

I also tried ^(.*)$ and ^(.+)$

which seems like it should do the job, because it would do this:

index.php -> index.php.php

but somehow, it doesn't work as expected.

So how do I update the above .htaccess script to disallow file extensions?

Mobile Redirect using htaccess from a directory to another

i have found this solution
i have this code originally posted here
http://ift.tt/1GDKKxl
i want to redirect mobile users from this

http://ift.tt/1HXcS1z

to this

http://ift.tt/1GDKIpd

i modified the code to suit my needs

####### for mobile 26/4/2015 ############
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
#  had to check, but I believe most mobile devices should send at
#  least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Check if we're not already on the mobile site
RewriteCond %{REQUEST_URI}          !^/dreams/mobile
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\smredir=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://ift.tt/1HXcPmz} [R,L]

it redirects me to the follwing URL

http://ift.tt/1GDKKxr

instead of this

http://ift.tt/1HXcPmF

i tested the code with another website and it worked in only one case
if i redirect from this

http://example.com/

to this

http://ift.tt/1xFqZk9

Update
i tried many ways until i found the best way to fix it by doing this
replace this

RewriteRule ^ http://ift.tt/1HXcPmz} [R,L]

with this

RewriteRule (.*) http://ift.tt/1GILxzV [R,L]

permalink breaks links in page

I have made my own permalink via htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase "/"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Now all works fine except the links in pages defaults to the first link in that page. Even form action link does that. What is wrong?

I have a zip file to download and a form directs to paypal.

URL showing wrong page after changing wordpress permalinks structure

I am using Book Your Travel wordpress theme, when I changed permalinks structure from default to postname, the URL automatically started showing wrong page (destinations) instead of going to homepage, here is my link I am talking about: http://ift.tt/1JBG4vF

If I set permalinks structure to default, then it works fine (homepage get load)

I've checked the .htaccess file, it contains wordpress basic htaccess rules.

Redirect a subdomain url that has a CNAME

I am looking to 301 redirect a single url on a subdomain to a url on the root domain. Eg:

'sub.domain.com/page' to redirect to 'domain.com/work/name'

I do not want to affect any other pages on the subdomain, the subdomain should operate as normal, aside from that one specific url.

The subdomain also has a CNAME record with the value 'shopname.bigcartel.com'

I tried the .htaccess suggested in my previous question here, but that was before I knew there was also a CNAME record active.

How can I achieve the redirection?

Thanks in advance. Darrell

Wamp, SlimPHP and Htacess

I am having issues with getting Slim to recognize the following:

$app = new \Slim\Slim();

$app->get('/', function () {
    echo "Hello";
});

$app->get('/:name', function () {
    echo "Hello";
});

$app->run();

It will see the first route just fine, how ever the second one returns a

Not Found

The requested URL /image-uploader/gg was not found on this server.

Which lead me to believe I didnt have the re-write mod enabled in wamp. So I enabled it and set AllowOverride to All

I then restarted wamp and visited localhost/image-uploader/ and I get Hello, how ever visiting the second route gives the error above.

Why? My htaccess is as such:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule index.php [L]
</IfModule>

MODX Revolution and Babel not working with .htaccess

I have been trying to figure out how to set up multilingual site with MODx and Babel. I'm pretty sure the contexts and the plugin are both set correctly but the .htaccess is probably causing me troubles. Here's what is looks like, I have the root set in a subfolder /test/voltage/admin2test and only one extra language (besides English) in /test/voltage/admin2test/cz/

RewriteEngine On
RewriteBase /test/voltage/admin2test/
# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^my-domain\.cz [NC]
#RewriteRule (.*) http://my-domain.cz/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.my-domain\.cz [NC]
#RewriteRule (.*) http://ift.tt/1Fyn1QA [R=301,L]
# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
# https://www.domain.com when your cert only allows http://ift.tt/1keluBG
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) http://ift.tt/1jmvRYG [R=301,L]
# The Friendly URLs part
# detect language when requesting the root (/)
#RewriteCond %{HTTP:Accept-Language} !^en [NC]
#RewriteRule ^$ en/ [R=301,L]
#RewriteRule ^$ cz/ [R=301,L]

# redirect all requests to /cz/favicon.ico
# to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(cz)/favicon.ico$ favicon.ico [L,QSA]

# redirect all requests to /cz/assets* to /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(cz)/assets(.*)$ assets$2 [L,QSA]

# redirect all other requests to /cz/* 
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(cz)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]

Enforce trailing slash policy htaccess with HTTPS

I was wondering if someone could lend a hand with a small .htaccess issue.

Inside the .htaccess file is this for example:

Options -Indexes 
RewriteEngine On 
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

# Normal
RewriteRule ^about$ ./about.html [L,NC]
RewriteRule ^news$ ./news.html [L,NC]
RewriteRule ^other$ ./other.html [L,NC]

This works great if you want to enforce HTTPS and NOT have a forward slash after domain.com/about

My question is:

How do I enforce HTTPS and add the forward slash at the end like so;

http://ift.tt/1oKZBtX

Thanks!

htaccess redirect to remove duplicate pages

I'm very new to this thing with htaccess rules.

I basically want two things.

  1. Redirect exampledomain.com to http://ift.tt/1qsWlqt. This works, the web host that is used had a FAQ page where they suggested the code I use. What doesn't work is this:

  2. Remove the way to access the "example" page from both "/index.php?p=example" and "/?p=example" to get better search engine ranks. If this means accessing that page from something like "/example", that's a bonus.

I basically want to remove the duplicate links that is caused by the /index.php-variant to get higher search engine ranks. Having prettier links isn't required, just a bonus, the most important thing is that I need to remove the duplicate links.

Here's the code anyway:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^exampledomain.com$
RewriteRule ^(.*)$ http://ift.tt/1bz6TC8 [R=301]

RewriteRule ^([^/]*)\.html$ /index.php?p=$1 [L]
RewriteRule ^([^/]*)\.html$ /?p=$1 [L]

Have I misunderstood the [L/R=301/*]-flags totally?

EDIT: Ok, to clarify. I want to remove duplicate urls to get higher search engine ranks. What my code above apparently did was to add yet another url to access the same page. Since I only want one way, is there any way to redirect instead of just pointing the "prettified" link to the original?

When I think about it, would a redirection of http://ift.tt/1wq9Ufs to exampledomain.com do the trick?

Thanks guys so far, sorry for being bad at explaining. :)

Virtualmin : multiple subdomains to single directory

I'm trying to point all my subdomains to a single directory. For instance...

  • en.mywebsite.com
  • de.mywebsite.com
  • uk.mywebsite.com

...must point to /home/mywebsite/public_html

This way, I want to catch the subdomain each time and update the language. (this is just an example, don't try to give another solution about languages)

I'm using Virtualmin and I don't know how to configure this.

Any idea ?

Thanks

htaccess page type redirect

I've been searching for this forever but no solution, probably I'm not asking the right question but anyways..

I'm developing a new HTML website and going to replace it with a .ASP site which is already on the domain and I want to make sure when the site is live, everyone who goes to "http://ift.tt/1DC4QUg" from Google will be 301 redirected to "http://ift.tt/1dtGtDi" (both for SEO and user experience purposes)

I need to have this on all pages. Page URLs and directories are ALL designed same as before, just page format is changing to HTML instead of .ASP

any .htaccess solutions for this?

thanks!

Forcing SSL on signup but removing SSL on non-signup pages

I am using wordpress and I have the following two functions defined in wp-config.php:

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);

But I am also wanting to force SSL on a signup page of http://ift.tt/1zpPY0d however if I navigate to the signup-page then navigate elsewhere on the website it keeps https enabled unless I go to the homepage...

I want the entire website to be forced to have www. and the force the entire website to be non-SSL with the exception of login forms, admin pages, signup-page and custompage

I tried the following rules:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^/?$ http://%{SERVER_NAME}/ [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(signup-page/.*)$ http://ift.tt/1droZBe [R=301,L]

But it doesn't quite work, the signup-page bit works but if I navigate to any other page it keeps the https...

Linking from a subfolder back to the root folder index.html file

I am having trouble linking from a subfolder index file back to my root folder index file.

I have a logo in the nav bar of example.com/blog that I would like to have link back to example.com

I have tested various linking options for the logo image including

<a href="../index.html">
<a href="http://www.example.com">
<a href="../">

And none of them seem to work. The logo image continues to link to http://ift.tt/1GFDWSS

The strange thing is that if I right click on the image and then select open in a new window/tab, then it will load example.com just fine.

I am at a complete loss.

Could this be something related to my .htaccess file?

Additional Info

I added a "Home" text link to the nav bar using the below syntax and it works perfectly.

<a href="http://www.example.com">Home</a>

The image for some reason will not link back to the rootfolder index.html file using the same syntax. It keeps loading http://ift.tt/1JTc0IO

.htaccess redirect from subfolder to root keeping paths

I'm migrating a site so I need to redirect all content from a http://ift.tt/1EDpybw to the www.newurl.com and keep all the links, for example:

http://ift.tt/1GFT2os

needs to redirect to

http://ift.tt/1GFT4wD

AND

http://ift.tt/1GFT2oA

needs to redirect to

http://ift.tt/1EDpyrS

my .htacess looks like this:

RewriteEngine on
RewriteRule ^subfolder/(.*)$ /$1 [R=301,L]

It is redirecting all http://ift.tt/1EDpybw to www.newurl.com/ but does not follow the old paths it just sends all request to home page

Treat file name as PHP GET

I currently have profiles on a test website setup to be viewed in this format:

http://ift.tt/1beR7vH

I would like to use this format:

http://ift.tt/1dN3if5

How would I treat the username as a variable in php, rather than a file?

Windows Azure: redirect website from www to non-www

I have this web.config file on my server.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                  <conditions>
                    <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                  </conditions>
                <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
            </rule>
            <rule name="Rule" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>

    <staticContent>
        <mimeMap fileExtension=".json" mimeType="application/json" />
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
    </staticContent>
</system.webServer>
</configuration>

I want to redirect URL from www to non-www. For example, if user types www.exmaple.com, it should go to https://example.com

How can I edit such a thing in above code. Thanks.

htaccess HTTPS only no redirect

I want to block port 80 (HTTP) completely and only allow HTTPS requests. I have found many examples of how to redirect from HTTP to HTTPS but I would prefer to display an error instead. I cannot block port 80 in my config file as my hosting provider does not allow me to modify these files. If possible, how can I achieve the same results with htaccess.

The reason for me wanting this on my api.domain.com is for added security after reading this article.

Quote from article...

Aside from abandoning HTTP Basic altogether there is an easy fix. close port 80 on your API host. This stops a connection being made dead in its tracks, preventing any credentials being sent in the clear

Convert a full wordpress site to HTTPS

I'm trying to get a wordpress site to HTTPS, but everything I try gives me a redirect loop. I've edited the htaccess, I've set it in PHP, I've even downloaded a wordpress plugin to convert it, but every method gives me a redirect loop error. I know that something has to be redirecting my https to http, but I don't know what. Here is my .htaccess file without any of the HTTPS settings in it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

And here's the PHP I'm trying to use in the header php file to conver the page to HTTPS:

if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}

URL issue - passing encoded characters like %2f and %2b

I am passing encrypted value through the URL using .htaccess file as shown below : URL : http://ift.tt/1GFBGrP

htaccess file : RewriteRule ^f1/(.+)$ index.php?id=$1 [NE]

The issue is the server respond by The requested URL was not found on this server. but when I replace %2f by / and %2b b s+ it works perfectly and I can see the content of the page.

it works also perfectly when I use the url without any rewriting as shown below : http://ift.tt/1GFBEjR

Could you please help with that and how can I modify my htaccess to make this work ? because I need to get the content using url rewriting as shown above

Thank you !!

htaccess redirect with RedirectMatch

I'm adding 301 redirect to my website, here is the htaccess content :

    RedirectMatch ^/gift/birthday/(.*) /gifts.html

the result in my browser is :

    http://ift.tt/1HRqQR6 

and I want :

    http://ift.tt/1DWmiDf

How can I do that ?

Redirect to a locale based on cookie

Our site uses custom locales. We save the locale a user selects in a cookie. How would I add to my htaccess file to accomplish redirecting to the proper locale based on the cookie? Our locales end up pre-pending /dallas, /fort-worth , /plano to the urls.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

htaccess - how to redirect url with params to base url

I am trying to redirect a page.html with params at the end to the base url without params. I know I am supposed to use mod rewrite but I can't get the rules figured out. Your help will be appreciated.

Here is the scenario: I tried this in htaccess and this rule didn't work redirect 301 "/page.html?p=2" http://ift.tt/1AdBue7

I understand from reading other posts on stackoverflow that I should write something like ^page.html$ http://ift.tt/1AdBue7 [QSA,NC,R=301,L]

The rules at the end [QSA,NC,R=301,L] however are incorrect. I can't figure it out. I simply want to do a 301 for this url with the p=2 parameter, and no other param.

And then process the remaining rules after this rule for other pages.

Words in different languages in the url

I have a website in 3 languages. I only have one page with the code and I change the text for each language.

Just a simplified example of the same page in English and French:

http://ift.tt/1bUhYyr
myDomain/tap.php/?lang=fr

To clean the url I use:

RewriteRule (myDomain)\/(\w{2})\/(.*) $1\/$3.php?lang=$2

This redirects the pages from:

myDomain/en/tap
myDomain/fr/tap

This works well but my question is: Is it possible to have words in different languages in the url? For instance, if some user writes in French:

myDomain/fr/robinet

Note: "robinet" is "tap" in French

could it be redirected to:

myDomain/tap.php/?lang=fr

(Remember that I just have 1 page for both languages, so myDomain/fr/robinet.php/lang=fr does not exist. I could make another redirect from that last to myDomain/fr/tap.php/?lang=fr but it doesn't seem like a very efficient solution) Maybe the solution is not in the .htaccess?

So my question is: how do you use words in different languages in the url?

301 Redirect only Posts not Pages

I am looking to redirect all the posts and not pages and custom post types from old domain to new domain. So all posts for instance http://ift.tt/1bUhXe2 should go to http://ift.tt/1J90N6R http://ift.tt/1bUhXe2 should go to http://ift.tt/1J90N6R

The pages i.e. http://ift.tt/1fi3man should still be functional

I can find alot of answers on moving blog into sub directory along with moving all the links but not for moving just the posts and not the pages

Edit There are over 1000 posts so I am looking for a dynamic way of doing this

Thank you for your help

Remove path & extension on URL via htaccess

I know this should be easy but it is beating me. After a site move I want to be able to remove the path to a file along with the extension (if any) and query string (if any) and index.php (if any) to leave just the file name. EG:

http://ift.tt/1J8KDdv
301 to >> http://ift.tt/1HR6iIt

http://ift.tt/1J8KDdz
301 to >> http://ift.tt/1HR6iIv

http://ift.tt/1J8KC9v
301 to >> http://ift.tt/1HR6k2X

http://ift.tt/1HR6iIA
301 to >> http://ift.tt/1J8KDdH

There are many different paths in the original site (with and without www), but if the file ends in .html (with the possibility of a query which has to go as well) I just want it redirecting 301 to the domain/filename

But... to make matters more complex, they can't redirect

http://ift.tt/1bUhY1y

This is because the category is part of the new system (it's wordpress).

Thanks for any help with this!

.htaccess add an extra word to add all my URLs

I need to a add a extra word right after my domain name to all my website URLs.

Lets say my url is http://ift.tt/1J90N6A, it should be http://ift.tt/1bUhWXq.

Is it possible to do it with .htaccess file ?

If so what should i add to my .htaccess file ?

Wordpress links on subdomain point to primary domain

I have an install of Wordpress on the root directory, and I've attempted to created a carbon copy of the install on a subdomain. However, when loading the subdomain and navigating through the pages, the links always point to the primary domain.

-I've double checked that the Wordpress settings for Site Url and Home Url contain the subdomain

-I don't have a .htaccess, instead I have a web.config. I've deleted this and had it recreated

-I've reset permalinks to default and back

Everything i've tried is yielding the same result. What am I doing incorrectly or overlooking? Your assistance is appreciated!

Thanks!

PHP Slim API 404 not found

I'm trying to create an API using php and php slim.

my folder structure:

API:

  • app -> app.js
  • libs -> Slim
  • v1 -> .htaccess and index.php

htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

index.php

require '.././libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app = \Slim\Slim::getInstance();

$app->get('/orderoverview/:customerID', function ($customerID) {
        echo "Hello " . $customerID;

});
$app->run();

This should be easy but every time I go to http://localhost/api/v1/orderoverview/2 I get a 404 Page Not Found.

BUT when I go to http://localhost/api/v1/index.php/orderoverview/2 I do get the result I want to become!

Any remarks or solutions?

Mask folder in url to file somewhere else

Is there a way in .htaccess to have a url that looks like www.example.com/one to instead of looking for a folder called one and find the index.html file in it, to just server one.html in the root folder? I've been trying to search for an answer but I'm not really sure what that would be called if it's even possible.

How to have different x-frame-options for different pages

I have added an X-FRAME-OPTION header to my .htaccess to prevent issues with click jacking.

<IfModule mod_headers.c>
    Header append X-Frame-Options "SAMEORIGIN"
</IfModule>

Now I am required to allow a certain route to be accessible via an iframe from outside domains. I'm using PHP and have tried overwriting the X-frame-option header via:

  header('X-Frame-Options: GOFORIT');

However it appears that the X-frame-option is not being overwritten but is instead being re-appended as per the following browser error (Chrome):

Multiple 'X-Frame-Options' headers with conflicting values ('GOFORIT, SAMEORIGIN') encountered when loading 'https://foo.com/baz/1'. Falling back to 'DENY'.

How do you go about overwriting the x-frame-options for certain pages?

Redirect 301 with params

I am redirecting traffic between old web and new web and I need to redirect 301 from /hotel.php?hotel=lasvegas&lng=es to http://ift.tt/1GEXFPK

How could be possible from htaccess? I have tried

Rewriterule ^hotel\.php\?hotel=lasvegas\&lng=es http://ift.tt/1GEXFPK [L,R=301]

I think my error is at regular expression. Can anyone help me?

architecture MVC script

I write social network with MVC architecture it work localhost (wampserver) correctly but when i upload it on real host i get this error in http://example.com/

Warning: require_once(views/index/index.php): failed to open stream: No such file or directory in /home3/farazenc/public_html/fb/views/index.php on line 14

Fatal error: require_once(): Failed opening required 'views/index/index.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home3/farazenc/public_html/fb/views/index.php on line 14

and my method not work for example when i go http://ift.tt/1HSFeIr must show register form but show 404

my main file: .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

index.php

<?php
session_start();
require_once './config.php';
require_once './lib/database.php';
require_once ('./lib/function.php');
$connect = database::connect();

function __autoload($classname) {
    $directrey = array('controllers', 'models');
    for ($i = 0; $i < sizeof($directrey); $i++) {
        if (file_exists($directrey[$i] . '/' . $classname . '.php')) {
            require_once ($directrey[$i] . '/' . $classname . '.php');
        }
    }
}

if (isset($_GET['url'])) {
    $url = $_GET['url'];
    $split = preg_split('/[\/\\\]/', $url);
    if (sizeof($split) == 1) {
        if (!file_exists('controllers/' . $split[0] . 'Controller.php')) {
            require_once ('./controllers/CheckPage.php');
            CheckPageController::check($split[0]);
        } else {

            $classname = $split[0] . 'Controller';
            $Controller = new $classname();
        }
    } elseif (sizeof($split) == 2) {
        if (file_exists('controllers/' . $split[0] . 'Controller.php')) {
            if (empty($split[1])) {

                $classname = $split[0] . 'Controller';
                $Controller = new $classname();
            } else {

                $classname = $split[0] . 'Controller';
                $Controller = new $classname();
                if (method_exists($Controller, $split[1])) {
                    $Controller->$split[1]();
                } else {
                    require_once ('./views/404.php');
                }
            }
        } else {
            require_once ('./views/404.php');
        }
    }
} else {
    require_once ('./controllers/IndexController.php');
    $IndexController = new IndexController();
}
if (isset($_POST['Action'])) {
    $ajax = new Ajax();
    $ajax->$_POST['Action']();
}

Controller.php

<?php

abstract class Controller {

    public function render($file) {
        if (!isset($_POST['Action'])) {
            global $split;
            $d = empty($split) ? 'index' : $split[0];
            $content = "views/$d/$file.php";
            require_once ('views/index.php');
        }
    }
    public function user_views($file){
        if (isset($_SESSION['user'])){
            require_once ('views/user/'.$file.'.php');
        }  else {
            require_once ('views/index.php');
        }
    }
    public function admin_views($file){
        if (isset($_SESSION['admin'])){
            global $split;
            $d = empty($split) ? 'index' : $split[0];
            $content = "views/$d/$file.php";
            require_once ("views/admin/admin.php");
        }  else {
            require_once ('views/admin/login.php');
        }
    }
}

IndexController.php

class IndexController extends Controller {

    public function __construct() {
        global $split;
        if (empty($split[1])) {
            $this->render('index');
        }
    }

    public function register() {
        $this->render('register');
    }
}

views/index.php:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>social network</title>
    <link href="<?php echo URL ?>/css/style.css" rel="stylesheet">
    <script type="text/javascript" src="<?php echo URL ?>/js/ajax.js"></script>
    <script type="text/javascript" src="<?php echo URL ?>/js/jquery.js"></script>
</head>
<body>
<div style="width:1000px;height:650px;margin:50px auto;">
    <div id="content">
        <?php
        require_once($content);
        ?>
    </div>
    <div id="ads" style="margin-right:15px;">
        <img src="<?php echo URL ?>/images/ads-120.jpg">
        <img src="<?php echo URL ?>/images/ads-120.jpg">
    </div>
</div>
</body>
</html>

what's the problem and how can i fix it ?

Redirect 301 issue

i´m trying to do a 301 redirect in my .htaccess with the following lines:

Options +FollowSymLinks
RewriteEngine On
Redirect 301 /oldpage http://ift.tt/1P5VpTN

The problem is, that the redirected url looks like this:

http://ift.tt/1drY0M5

and that naturally causes a 404 on my site. Does anybody know, what the problem could be? Thanks a bunch!

disallow access of internal files in liferay

In liferay I have
--tomcat
  --webapps
   --myimages
   --my-portlet
So using code in my-portlet I have given links to given file in myimages folder for a specific user.
Link would be
http://localhost:8080/myimages/User1.jpg

Problem Statement: I have to restrict a user (rather than defined role in liferay) so that s/he should not be able to access any of the files in myimages folder as s/he user hits on direct above link.

What I have tested:

  1. I have checked .htaccess file will NOT be useful since liferay has tomcat rather than apache server.
  2. Created a filter class by which I can intercept any request made should process through.
  3. openLDAP can not use since we are having separate authentication mechanism.
    So if anyone has idea how to deal with this security issue, please suggest me.

Magento redirect loop in maintenance mode

I just switched on my maintenance mode extension on Magento and it has created a redirect loop in the back end and front end of my website, realboysrealtoys.co.uk, for some reason. I've searched through the file but cannot find anything.

Here's my .htaccess file incase anyone can spot anything.

############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
## it might be /cgi-bin/php-cgi

#    Action php5-cgi /cgi-bin/php5-cgi
#    AddHandler php5-cgi .php

############################################
## GoDaddy specific options

#   Options -MultiViews

## you might also need to add this line to php.ini
##     cgi.fix_pathinfo = 1
## if it still doesn't work, rename php.ini to php5.ini

############################################
## this line is specific for 1and1 hosting

    #AddType x-mapp-php5 .php
    #AddHandler x-mapp-php5 .php

############################################
## default index file

    DirectoryIndex index.php

<IfModule mod_php5.c>

############################################
## adjust memory limit

#    php_value memory_limit 64M
    php_value memory_limit 256M
    php_value max_execution_time 18000

############################################
## disable magic quotes for php request vars

    php_flag magic_quotes_gpc off

############################################
## disable automatic session start
## before autoload was initialized

    php_flag session.auto_start off

############################################
## enable resulting html compression

    #php_flag zlib.output_compression on

###########################################
# disable user agent verification to not break multiple image upload

    php_flag suhosin.session.cryptua off

###########################################
# turn off compatibility with PHP4 when dealing with objects

    php_flag zend.ze1_compatibility_mode Off

</IfModule>

#<IfModule mod_security.c>
############################################
## disable POST processing to not break multiple image upload
#
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

<IfModule mod_deflate.c>

############################################
## enable apache served files compression
## http://ift.tt/uuJeEP

    # Insert filter on all content
    ###SetOutputFilter DEFLATE
    # Insert filter on selected content types only
    #AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

    # Netscape 4.x has some problems...
    #BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    #BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    #BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don't compress images
    #SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary

</IfModule>

<IfModule mod_ssl.c>

############################################
## make HTTPS env vars available for CGI mode

    SSLOptions StdEnvVars

</IfModule>

<IfModule mod_rewrite.c>

############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on

############################################
## you can put here your magento root folder
## path relative to web root

    #RewriteBase /magento/

############################################
## uncomment next line to enable light API calls processing

#    RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]

############################################
## rewrite API2 calls to api.php (by now it is REST only)

    RewriteRule ^api/rest api.php?type=rest [QSA,L]

############################################
## workaround for HTTP authorization
## in CGI environment

    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks

    RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
    RewriteRule .* - [L,R=405]

############################################
## redirect for mobile user agents

    #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
    #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
    #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]

############################################
## always send 404 on missing files in these folders

    RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

############################################
## never rewrite for existing files, directories and links

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

############################################
## rewrite everything else to index.php

    RewriteRule .* index.php [L]

</IfModule>


############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead

    AddDefaultCharset Off
    #AddDefaultCharset UTF-8

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://ift.tt/WTMwpS

    ExpiresDefault "access plus 1 year"

</IfModule>

############################################
## By default allow all access

    Order allow,deny
    Allow from all

###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version

    <Files RELEASE_NOTES.txt>
        order allow,deny
        deny from all
    </Files>

############################################
## If running in cluster environment, uncomment this
## http://ift.tt/1iWN9aw

    #FileETag none

I have no idea so any help would be greatly appreciated.

Thanks, Charlie

.htaccess RewriteRule for image URL

At the moment i have the following .htaccess rewrite rule:

RewriteCond %{HTTP_HOST} ^blitz.example.com.s3-ap-southeast-1.amazonaws.com$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]

I am trying to rewrite the following URL so that it points to the actual URL (see 2nd link below):

http://ift.tt/1GA7IbF

Where as i need to create a RewriteRule that points to the real actual URL which is:

http://ift.tt/1Edev7o

Can anyone help me with this ? I am really confused with this RewriteRule and regex.

EDIT

I want to use URLs like the followings :

http://ift.tt/1GA7IbF

and rewrite it with another domain like the followings :

http://ift.tt/1Edev7o

So far if i use the following html tag

<img src="http://ift.tt/1GA7IbF">

it returns 404

EDIT 2

Interestingly enough the following code also returns 404 error

<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^blitz.example.com.s3-ap-southeast-1.amazonaws.com$
RewriteRule ^(.*)([0-9]+)([0-9]+)([0-9]+)([0-9]+)-([a-zA-Z0-9_\-/.]+)/([a-zA-Z0-9_\-/.]+)$ img/p/$2/$3/$4/$5/$2$3$4$5-$6.jpg [L]
</IfModule>

EDIT 3

Out of desperation, i put only the following code on my .htaccess:

<IfModule mod_rewrite.c>

RewriteRule ^(.*)([0-9]+)([0-9]+)([0-9]+)([0-9]+)-([a-zA-Z0-9_\-/.]+)/([a-zA-Z0-9_\-/.]+)$ img/p/$2/$3/$4/$5/$2$3$4$5-$6.jpg [L]

</IfModule>

There is no other code in .htaccess, yet it still returns 404.

Nginx rewrite doesn't work when I try to match a file

I need to convert in Nginx these .htaccess rules, but when I try to target the filename and its extensions, Nginx doesn't match it. I really don't understand why of this behavior.

RewriteRule ^(.*?)(test_mod_rewrite) /$1media/plg_jchoptimize/assets/modrewrite.php?q=$2
RewriteRule ^(.*?)(gz|nz)/([^/]+)/([^/]+)/([^/]+)\.(js|css)$  /$1media/plg_jchoptimize/assets/jscss.php?f=$5&type=$6&gz=$2&d=$3&i=$4

I converted these rules in Nginx:

location /media/plg_jchoptimize/assets/ {
    rewrite ^/(test_mod_rewrite) /media/plg_jchoptimize/assets/modrewrite.php?q=$1;
    rewrite ^/(gz|nz)/([^/]+)/([^/]+)/([^/]+)\.(js|css) $/$1media/plg_jchoptimize/assets/jscss.php?f=$4&type=$5&gz=$1&d=$2&i=$3;
}

The example URL is:

/media/plg_jchoptimize/assets/gz/30/0/d8604b25d503f1dcbb035ec731857648.css

What I'm wrong?

How to Converting this specific apache “RewriteCond” rules to nginx

I am moving from an Apache to nginx and need to convert RewriteCond rules to nginx.

DirectoryIndex /public/index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) $1 [L]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^(.+) /public/$1 [L]

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /public/index.php?q=$1 [L,QSA]

#RewriteRule !\.(js|ico|gif|jpg|png|css|xml|xslt)$ /public/index.php

.htcaccess in Apache not working

I enabled mod_rewrite and want to redirect one of my local virtual host websites to google.com for practice.

I created an .htcaccess file in my virtual directory (/var/www/http://ift.tt/1GA3sbW) and gave permissions to .htcaccess by adding the following code to my virtual host's (example.com) config in /sites-available/.

 <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
 </Directory>

I am now attempting to use mod_rewrite by adding code to the .htcaccess file but have had no success thus far. Is there any way to check if .htcaccess is working? If it is, how do I redirect using mod_rewrite?

.htaccess regular expression syntax

sorry for my bad English. I would exclude from my website every referral spam that contains the word "buttons" because I'm tired of all "social-buttons", "buttons-for-your-website", "my-brother-buttons" ecc. that I can see in my Google Analytics report. I'm not into Regular Expression, but I thought of something like this:

RewriteCond %{HTTP_REFERER} ^http://ift.tt/1DJdMby [NC,OR]

Is it wrong? Could this method exclude this kind of referral? I didn't tested it: I don't know how to do. Thank you very much :)

How to redirect a page that does not exist anymore in Wordpress?

When I first made my Wordpress site I didn't know it's a good idea to use slugs instead of ids in links. I had a page back then that had the address:

http://ift.tt/1bSJlsS

When I made a template for a popular e-commerce platform in my country I included said link. A year later the site crashed and I had to rebuild it. Needless to say, the page in question was assigned with a different ID. I cannot change it on e-commerce platform (that would require thousands of individual changes - that is not an overstatement).

So, can I somehow redirect the /?page_id=50 to a different page? The problem is that no page has this particular ID.

Is there any way? I tried .htaccess redirection but it didn't work or maybe I did something wrong.

Please help.

url redirect exact match including params

i would like to make a 301 redirect and from an old website using the exact exact url with no extra parameters.

example:

/en-direct.php?page=7

to go to:

http://ift.tt/1bCrqWC

and page:

/en-direct.php?page=8

to go to:

http://ift.tt/1bSFCLX

i used:

redirectMatch 301 ^/en-direct.php$ http://ift.tt/1bSFD2d
redirectMatch 301 ^/en-direct.php?page=7$ http://ift.tt/1bCrqWC
redirectMatch 301 ^/en-direct.php?page=8$ http://ift.tt/1bSFCLX

however: i get http://ift.tt/1bSFD2d every time with all the parameters from the redirect page (example - http://ift.tt/1bCroOr )

any help will be much appreciated.

Trying to remove directory names from application URL

My badluck I'm a UI developer and given the task of URL rewriting please help me.

I've this URL with me /abc/def/ghi/somefile.php?id=1 I want it to just somefile?id=1

I do have this code in my .htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteRule ^/abc/def/ghi/(.*)$ /$1 [L,NC,R]

but after uploading the htaccess to server this is giving me 404 error after removing the /abc/def/ghi/ part.

Any help is greatly appreciated.

.htaccess file does'nt work properly

I have create the .htaccess in following way

 RewriteEngine on
RewriteBase /school1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1 [L,QSA]

I mean that when user hit the 'school1/schools/schools' they will get the contents of 'school1/index.php?path=schools/schools' It is working properly but css js and images requests are going to the school1/schools/[js|css|img]/... as per directory instead of school1/[js|css|img]

I m not getting why they are getting the schools part from the url. if i m fire http://ift.tt/1JRkDnd it renders properly but when i fire http://ift.tt/1FwvFiu

Please help me I have wasted my long time for this problem. If you want any extra info please comment it.

Forcing http on a url using .htaccess

I'm using .htaccess to force https on my site and it's working fine. But I need to force http on a single url (example: http://ift.tt/1FwvHqw). I don't know that how to do this ? I'm not sure how to handle this.

Please help....

mardi 28 avril 2015

Php htaccess 404 Not Found Page

I have a website and its link structure is like that;

http://ift.tt/1bcM4Mo -> page.php
site.com/blog/ -> blog homepage
http://ift.tt/1HXAgvW -> post page

and index, contact page and so on.

All I want to do is create a htaccess file and check all pages that doesn't exit.

But I don't know how to check pages if they exist or not.

For example, http://ift.tt/1bcM4Mq -> this page exists, I can check it. but I can not check the page like that http://ift.tt/1HXAgvY

Any idea?

How to rewrite these url on htaccess

i want to rewrite these URL

getimage.php?videoid=myquery

to

img/myquery

i try this ht access code but after this its show empty page

RewriteEngine On
RewriteBase /
RewriteRule ^img/(.+)  getimage.php?videoid=$1

please tell me how to set it

Mobile Redirect using htaccess from a directory to another

i have found this solution
i have this code originally posted here
http://ift.tt/1GDKKxl
i want to redirect mobile users from this

http://ift.tt/1HXcS1z

to this

http://ift.tt/1GDKIpd

i modified the code to suit my needs

####### for mobile 26/4/2015 ############
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)noredirect=true(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:%{HTTP_HOST},S]

# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
#  had to check, but I believe most mobile devices should send at
#  least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Check if we're not already on the mobile site
RewriteCond %{REQUEST_URI}          !^/dreams/mobile
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie}        !\smredir=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://ift.tt/1HXcPmz} [R,L]

it redirects me to the follwing URL

http://ift.tt/1GDKKxr

instead of this

http://ift.tt/1HXcPmF

i tested the code with another website and it worked in only one case
if i redirect from this

http://example.com/

to this

http://ift.tt/1xFqZk9

use htaccess file to prevent link to specific external site?

I have a social network using a popular php framework. MY competition is trying to spam my site with links to his site. IS there a way to use htaccess to prevent links leading to his site? have www.his_domain.com clicks lead to google or right back to my home page?

Execute PHP Code on ASP Page

Does anyone know if there is a file handler (or some other directive) that can be added to an .htaccess file that will force PHP code to execute within an ASP page? It's working currently on client's site but it will not on new server at GoDaddy under Plesk.

This is what's currently in the .htaccess file on the site that works, but it is not working on the new server.

<FilesMatch "\.asp$">
    ForceType application/x-httpd-php
</FilesMatch>

Thanks.

If I use mod_deflate, will stripping whitespace in my outputted HTML files also help increase speed?

I am already using HTACCESS through Apache to GZIP the contents of all HTML/CSS/JS files that are served. I use a program called Koala that automatically minifies JS and CSS output to have zero whitespace, but since I am using PHP to dynamically generated the HTML code, there is no clear way to eliminate unnecessary whitespace in the HTML file that ultimately gets served to the browser. However, since I am already GZIPping the contents of the file, is this even necessary at all?

URL rewrite htaccess in xenforo not working

In my simple module, I am trying to rewrite the url using htaccess this is what I have: http://localhost/xf/film?ep=2 And I want: http://localhost/xf/film/episode-2

Mod rewrite is enable. Here is my .htaccess file:

RewriteEngine On

#   If you are having problems with the rewrite rules, remove the "#" from the
#   line that begins "RewriteBase" below. You will also have to change the path
#   of the rewrite to reflect the path to your XenForo installation.
RewriteBase /xf

#   This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^film/episode-([0-9]+)$ film?ep=$1 [NC,L]

Getting 403 Forbidden error While redirecting to another Url/Website

I am trying to redirect to another online shopping website, using the similar link below:

http://ift.tt/1DzzXQehttp://www.google.com

But When I click on the link I am getting 403 Forbidden error.

In local machine it is working fine. I am getting this issue only after moving the code to web hosting server.

I am using Hostgator shared hosting.

If I am using without http as below, in the redirect url it is working fine.

http://ift.tt/1DzzVrI

Do I need to modify anything in .htaccess?

Please help me to resolve this issue.

What is the most efficient, safest and ultimately best be way of forcing WWW & HTTPS (SSL) on a specific domain, entire site & specific folder

What is the most efficient, safest and ultimately best be way of forcing WWW & HTTPS (SSL) on a specific domain, entire site & specific folder.

I'm essentially looking for three rewrite rules

  • Spesific Domain (exampledomain.com)
  • Spesific Folder (/testfolder/)
  • Entire Website (All contents within public_html)

Here are a bunch of rules that I've gathered from around the internet but this is only a small portion of what's listed here and there...

Some of these must have negative side effects/downsides.

##Rule 1
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTP_HOST} ^exampledomain.com
RewriteRule ^(.*)$ http://ift.tt/1P4zfRF [L,R=301]

##Rule 2
RewriteCond %{HTTP_HOST} ^exampledomain\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ http://ift.tt/1P4zfRF [R,L]

##Rule 3
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.exampledomain\.com$ [NC]
RewriteRule ^ https://www.exampledomain.com%{REQUEST_URI} [R=301]

##Rule 4
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ http://ift.tt/1P4zfRF [R,L]

##Rule 5
RewriteCond %{HTTP_HOST} ^exampledomain\.com$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ http://ift.tt/1P4zfRF [R,L]

##Rule 6
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]

##Rule 7
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

##Rule 8
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^exampledomain\.com$ [NC]
RewriteRule ^.*$ https://www.exampledomain.com%{REQUEST_URI} [R,L]

Dobule Word with Hyphen(-) Htaccess Redirection Not works in PHP

Recently I have created a .htaccess redirection to my dynamic site. In the redirection single-word url works perfectly. example: http://ift.tt/1Dzvw83 (no issue) At the same time this link not works http://ift.tt/1Jzi5gJ (issue)

I have stored state name andhra pradesh as "Andhra Pradesh" in my db and i have used "strtolower" and "str_replace(' ', '-')" functions to get the result as "andhra-pradesh.php" in my php file.

Here it is my htaccess code

RewriteEngine On

RewriteCond %{REQUEST_URI} /pincode/(.*).php$
RewriteRule ^pincode/(.*).php$ pinstate.php?st=$1 [L]

please help me to fix this issue.

Options -Indexes displays seemingly random string

I am trying to disallow directory browsing by adding Options -Indexes to a .htaccess file on my website. When I try to load a page with directory browsing turned off, all that is shown is a seemingly random string on a blank page. I want disallowed pages to show a 403 error.

The string is: ‹³É(Éͱãâ´ÉHML±ãRN›’Ì’œT;c·ü¢¤Ì””Ô<}ˆ X…>BµMR~J%LcsiqI~®HoJ~rinj^‰ž~LD1P?ÈV&Ž§­|

The .htaccess file:

Options -Indexes

SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* – [F,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^awkwardpetsiblings\.org [NC]
RewriteRule (.*) http://ift.tt/1AdLJj7 [R=301,L]
RewriteCond %{HTTP_HOST} ^awkwardpetsiblings\.net [NC]
RewriteRule (.*) http://ift.tt/1AdLJj7 [R=301,L]
RewriteCond %{HTTP_HOST} ^awkwardpetsiblings\.x10host\.com [NC]
RewriteRule (.*) http://ift.tt/1AdLJj7 [R=301,L]

ErrorDocument 403: "/php/err/403.php"
ErrorDocument 404: "/php/err/404.php"
ErrorDocument 500: "/php/err/500.php"

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE image/svg
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

<ifModule mod_deflate.c>
  <filesMatch ".(css|js|x?html?|php|svg)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType text/css "access plus 86400 seconds"
  ExpiresByType text/javascript "access plus 86400 seconds"
  ExpiresByType application/javascript "access plus 86400 seconds"
  ExpiresByType application/x-javascript "access plus 86400 seconds"
  ExpiresByType image/x-icon "access plus 604800 seconds"
  ExpiresByType image/gif "access plus 604800 seconds"
  ExpiresByType image/jpeg "access plus 604800 seconds"
  ExpiresByType image/png "access plus 604800 seconds"
  ExpiresByType font/woff2 "access plus 31560000 seconds"
  ExpiresByType application/x-font-woff "access plus 31560000 seconds"
</IfModule>

Header unset ETag
FileETag None

The webpage is http://ift.tt/1zbr1Fl. Can anyone tell me what is going on?

mod_rewrite issue with single file no query string

Trying to use mod-rewrite to alter the address bar versus the actual page that's being loaded. It works great when I have a query string to use, but I need to do it without a query string, just a straight up pretty url.

It seems to be that without a query string, straight mod_rewrites to files just shows the actual filename with extension.

Here's what my htaccess looks like:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

This works:

RewriteRule ^admin/account/([^/]*)/$ /adminconfig/account.php?id=$1 [L]

This doesn't:

RewriteRule ^admin/account/$ /adminconfig/account.php [L]

What's happening is that in the address bar I see:

http://ift.tt/1AdITL5

should be:

http://ift.tt/1HPsdQn

Stop SQL Injection through .htaccess

We have been the target of some nasty SQL injection attacks - all hitting the same page, and using roughly the same injection parameters. They aren't actually getting anywhere, but when they hit the same page it takes up server resources and slows everything down.

I've attempted using a generic SQL Injection code block like the one found here, but not 100% it's actually working.

I've taken a snippet of the URL they are hitting, see below:

b%27%20and%20if%28Length%28%28database%28%29%29%29%3C24%2CBENCHMARK%281206122%2CMD5%280x41%29%29%2C0%29%20and%20%27x%27%3D%27x

I just want to send them to an error page or something, but not quite sure how to implement what I am after.

Any and all help appreciated.

On a side note, it is not a Wordpress directory they are hitting, so Wordpress security plug-ins are no good.

Cheers, BH-Tech

I'd also add that the injection parameters are not in a query string. The requests are similar to below:

/directory/hospitals/http://www.domain%27%20and%20if%28Length%28%28select%20distinct%20table_name%20from%20%60information_schema%60.tables%20where%20table_schema%3D%27mysql%27%20limit%200%2C1%29%29%3D13%2CBENCHMARK%281925550%2CMD5%280x41%29%29%2C0%29%20and%20%27x%27%3D%27x.com/directory/hospitals/

Linking from a subfolder back to the root folder index.html file

I am having trouble linking from a subfolder index file back to my root folder index file.

I have a logo in the nav bar of example.com/blog that I would like to have link back to example.com

I have tested various linking options for the logo image including

<a href="../index.html">
<a href="http://www.example.com">
<a href="../">

And none of them seem to work. The logo image continues to link to http://ift.tt/1GFDWSS

The strange thing is that if I right click on the image and then select open in a new window/tab, then it will load example.com just fine.

I am at a complete loss.

Could this be something related to my .htaccess file?

URL Rewriting and Laravel 4 Routes not working on server?

I bet this question has been asked time and time again, but I just can't seem to get an answer. Anyway, here is my situation. I have a domain, lets say example.com. Example.com works fine, everything works as it should. However, if I navigate to Example.com/about, which works on my local machine, I get a 404 error. However, if I go to http://ift.tt/TUkjiV, the about page works fine. I know this must be a mod rewrite issue. I have enabled mod rewrite and restarted my server to no avail. Anyway, here is some code:

Virtual Host:

<VirtualHost *:80>
  ServerName example.com
  DocumentRoot "/var/www/example/public"
  <Directory "/var/www/example/public">
    AllowOverride all
    Allow from All
  </Directory>
</VirtualHost>

And here is my .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

I'm using Ubuntu 14.04 on a Digital Ocean Droplet.

Thanks!

.htaccess file editing (Multi Rule + Referrer Attack)

I am Turk. My English is a little poor. (Sorry)

My Web Site => Opencart (mysiteexample.com) My Blog Site => WordPress(blog.mysiteexample.com),

Getting referrer spam attacks.

My problem:

There are many rules in my .htaccess file. I can't stop referrer attack! How can I fix it?

Is this the right file? please help me.

my .htaccess file : Link-1 or Link-2

Codeigniter not woking on subdomain

i have a fresh copy of CodeIgniter configured on my local server and works fine. but when i upload in http://ift.tt/RRkJpv it shows an error.

An Error Was Encountered

Unable to determine what should be displayed. A default route has not been specified in the routing file.

Is there a problem with my hosting provider or i can fix this using a .htacess file?

i have no clue what i am dealing with. any help is appreciated.

Thanks

URL rewrite rules with Apache

I have a .htaccess file like this:

RewriteEngine On

RewriteRule ^([\w-]+)/([\w-]+)/?$ profile.php?username=$1&w=$2 [QSA,L]
RewriteRule ^([\w-]+)/?$ profile.php?username=$1 [QSA,L]
RewriteRule ^p/timeline timeline.php [NC,L]
RewriteRule ^p/notifications notifications.php [NC,L]

I can use my url like this

http://ift.tt/1gQRvOD
or
http://ift.tt/1DT7XYj

But some rules does not work. For example:

http://ift.tt/1DUhZs8

There is a problem with url which include mysite.com/p/..

Anyone can help me?

Using .htaccess to Rewrite URL to lowercase and remove existing extension but skip if .pdf

Need a URL rewrite/redirect that will take a URL like:

http://ift.tt/1GFlQjK

and rewrite it to

http://ift.tt/1DyPfVh

BUT don't rewrite the URL if it ends in .pdf.

We can't use RewriteMap because we are in a shared environment.

All Google search result urls pointing to mobile home page

I have gone through most articles here and finding no joy. My situation is as follows

  • I have main website with its htaccess file
php_value display_errors 0
php_value error_reporting 30719
php_flag display_errors off

RewriteEngine On

#without www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#with www
#RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)
#RewriteRule ^(.*) http://www.%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

<Files *.ini>
        order deny,allow
        deny from all
</Files>

#RewriteCond %{HTTP_USER_AGENT} Android|Blackberry|iPad|iPhone|ipod|iemobile|opera\ mobile|palmos|webos|googlebot-mobile
#RewriteCond %{REQUEST_URI} !^/mobile/
#RewriteRule .* /mobile/ [R]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

<IfModule mod_deflate.c>
#The following line is enough for .js and .css
AddOutputFilter DEFLATE js css
AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html
 
#The following lines are to avoid bugs with some browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary
</IfModule>
 
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300
#set catche for one month
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
ExpiresByType text/x-javascript A2592000
ExpiresByType application/javascript A2592000
ExpiresByType application/x-shockwave-flash A2592000
</IfModule>
## EXPIRES CACHING ##

## EXPIRES CACHING ##
 <IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
        Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"
</FilesMatch>

<FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public" 
</FilesMatch>
<FilesMatch "\.(css)$">
Header set Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "private"
</FilesMatch>
<FilesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</FilesMatch>
</IfModule>

<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>

Header unset ETag
FileETag None
<ifModule mod_headers.c>
Header unset Last-Modified
</ifModule>
  • I have a mobile website with files in /mobile directory with htaccess as well
RewriteEngine On

#without www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#with www
#RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)
#RewriteRule ^(.*) http://www.%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

<Files *.ini>
        order deny,allow
        deny from all
</Files>

Questions - Currently when i open a google search result url, they all point to the mobile site home page instead of the mobile version of the url. Please help

Hide URL through htaccess rewrite

Perhaps this is impossible to achieve but this is what I would like:

Keep URL the same but load page from alternative site. So MY DOMAIN is what is the input URL in my browser. The website is loaded through SITE DOMAIN with that specific URL But MY DOMAIN needs to stay visible and not the long SITE DOMAIN URL

With below settings I see the full URL of SITE DOMAIN but I need to keep it at MY DOMAIN. So the full SITE DOMAIN URL needs to be hidden and only show the short MY DOMAIN.

RewriteCond %{HTTP_HOST} ^(MY DOMAIN)$ [OR]
RewriteCond %{HTTP_HOST} ^www.(MY DOMAIN)$
RewriteRule ^/?$ "http://(SITE DOMAIN)/cms/?option=com_content&view=article&id=150&Itemid=516" [R=301,NC,L]

Editing htaccess to allow subdomain access

I've setup a subdomain in my bluehost cpanel as 'blog'. So that I can access it via blog.website.com. But after setting this up in cpanel and going to blog.website.com I get a 403 permission denied error. Bluehost support tells me there's something wrong with my htaccess file but they don't know what.

So I'm here with you knowledgeable folks. How can I add a subdomain to my htaccess file so that something like blog.website.com works?

Thanks!

htaccess index.html file in subfolder

I've read countless posts about this and still can't get it working. I published my site via FTP to my account. However, my main index.html is located within a few folders.

So within my public_html directory there is a folder called theme and within that a folder called template and within that a folder called onepage2 which is where my index.html and other relevant html files are located.

If I access that file by navigating through the web broswer (clicking through the directories) it shows up fine (minus a picture not uploading).

How can I make it so that if I go to my website swipeapp.net it takes me right to that file in that subfolder of public_html/theme/templates/onepage2 and then index.html

Here is my .htaccess file code:

# Do not change this line.\
RewriteEngine on\
# Change yourdomain.com to be your primary domain.\
RewriteCond %\{HTTP_HOST\} ^(www.)?swipeapp.net$\
# Change 'subfolder' to be the folder you will use for your primary domain.\
RewriteCond %\{REQUEST_URI\} !^public_html/theme/templates/onepage2/\
# Don't change this line.\
RewriteCond %\{REQUEST_FILENAME\} !-f \cb1 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \uc0\u8232 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 RewriteCond %\{REQUEST_FILENAME\} !-d\
# Change 'subfolder' to be the folder you will use for your primary domain.\
RewriteRule ^(.*)$ public_html/theme/templates/onepage2/$1\
# Change yourdomain.com to be your primary domain again. \cb1 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \uc0\u8232 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 # Change 'subfolder' to be the folder you will use for your primary domain \cb1 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \uc0\u8232 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 # followed by / then the main file for your site, index.php, index.html, etc.\
RewriteCond %\{HTTP_HOST\} ^(www.)?swipeapp.net$ \cb1 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \uc0\u8232 \cb3 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 RewriteRule ^(/)?$ public_html/theme/templates/onepage2/index.html [L]\
}

Been working on this all day! Thanks!

.htaccess: forward to url but keep current url

I'm trying to forward an url (url1) to another url (url2). But i dunt ant the users to see url2

I've tried a couple of things and got this to do a forward. It doesn't change url1 to url2 tough:

RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_URI} ^/url1
RewriteRule ^(.*)$ url2 [L] 

Redirect single subdomain url to root domain url

I am looking to 301 redirect a single url on a subdomain to a url on the root domain. Eg:

'sub.domain.com/page' to redirect to 'domain.com/work/name'

I do not want to affect any other pages on the subdomain, the subdomain should operate as normal, aside from that one specific url.

How would this be achieved the .htaccess?

Thanks in advance. Darrell

Hide one of parameters in url

I have an url looked like this:

http://ift.tt/1bbogbL

And I have used the following rules in .htaccess to hide those parameters

#RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteRule ^([^/\.]+)/([^/\.]+) /page.php?id=$1

and i got this:

http://ift.tt/1bbogbN

How can I have an url looks like:

http://ift.tt/1zaDE3t ??

my php codes are:

echo '<li class="link actived"><a href="http://' . $_SERVER['HTTP_HOST'] . '/' . $row['ID'] . '/' . $secure->toAscii($row['TYPE']) . '">' . $row['TYPE'] . '</a></li>';

Best!!

How to give a subpage it's own domain name?

This may be a stupid question, but is it possible to make example.com display `mysite.com/example'

Useful for having projects within a project with their own domain, or a landing page with it's own domain.

Are there some clever htaccess rules and domain name and server configurations to make this work?

Creating SEO Friendly URLs with .htaccess and php

I'm trying to generate SEO friendly URLs using PHP by using a rewrite in our .htaccess file, but I can't get it to work (I've researched many of the related topics on StackExhange and elsewhere, but to no avail).

I'm attempting to make the content of this URL: http://ift.tt/1Ekmrnv

...also display on the cleaner URL version here: http://ift.tt/1bAJ11a

I'm using the following code in my .htaccess file:

RewriteEngine on
RewriteRule ^surety-bonds/([a-zA-Z]+)$ city.php?state=$1&city=$2 [L,NC]

Any idea why the cleaner URL displays a 404 error?

Thanks!