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.