Search code examples
.htaccessmod-rewritemodx

.htaccess redirect index.php?q=* to index.php?q=* on another domain


Why each page redirects to domain? I move dkcherta.ru -> dkchertanovo.ru and want for example http://dkcherta.ru/index.php?id=80 -> http://dkchertanovo.ru/index.php?id=80

My .htaccess:

    Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?dkcherta\.ru$ [NC]
RewriteRule ^ http://dkchertanovo.ru/%{REQUEST_URI} [L,R=301]

RewriteRule ^rss_afisha[/]?$ /index.php?id=230 [L]
RewriteRule ^rss_news[/]?$ /index.php?id=231 [L]

ErrorDocument 404 http://dkchertanovo.ru/
# For full documentation and other suggested options, please see
# http://svn.modxcms.com/docs/display/MODx096/Friendly+URL+Solutions
# including for unexpected logouts in multi-server/cloud environments

RewriteBase /              

# Сливка доменного имени 
#RewriteCond %{HTTP_HOST} ^dkchertanovo\.ru$ [NC]
#RewriteRule ^(.*)$ http://www.dkchertanovo.ru/$1 [R=301,L]

RemoveHandler .php .htm .html
AddType application/x-httpd-php .php .htm .html
AddHandler application/x-httpd-php .php .htm .html
php_flag register_globals off

# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]

# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 


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


# Reduce server overhead by enabling output compression if supported.
#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5

Solution

  • You don't need multiple lines of these:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On 
    

    Just put only once at the top and it should be effective for rest of the file.

    Then to solve your problem move this rule on top of all other rules in your .htaccess file:

    RewriteCond %{HTTP_HOST} ^(www\.)?dkcherta\.ru$ [NC]
    RewriteRule ^ http://dkchertanovo.ru%{REQUEST_URI} [L,R=301]