Перейти к содержимому
Калькуляторы

Хитрый rewrite для Apache

Есть 2 сайта в одной папке: старый и новый. Так же есть 2 индексные странички: index.php (для нового сайта, соответственно отдаётся по дефолту) и index2.php (индексная страничка от старого сайта).

Нужно что бы URL http://site[dot]com/posts отдавался через старую индексную страничку index2.php. Собственно вся сложность в том, что /posts - не является ни папкой, ни даже rewrit'ом из htaccess, а жёстко зашита в коде сайта.

То есть что-то наподобии такого: http://site[dot]com/posts -> http://site[dot]com/index2.php/posts

Не могу даже понять с какой стороны подступиться.

Заранее спасибо.

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Раньше был rewrite на index.php ?

 

Т.е. неплохо бы увидеть сначала набор правил для старого сайта

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Что значит был? Ниже htaccess от старого сайта, для которого работал нормаль URL /posts

 

SetEnv KOHANA_ENV PRODUCTION
#SetEnv KOHANA_ENV DEVELOPMENT

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
       Order Deny,Allow
       Deny From All
</Files>


# Assets versioning
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d{9,11})\.(js|css|png|jpg|gif)$ $1.$3 [L]


# add trailing slash to everything except article and CMS links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin.*
RewriteCond %{REQUEST_URI} !^/\d{4}\-\d{2}/.*
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,7}|/|#(.*))$
RewriteRule ^(.*)$ /$1/ [R=301,L]

# remove trailing slash from article links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/\d{4}\-\d{2}/\d.*
RewriteRule ^(.*)/$ /$1 [R=301,L]
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

<IfModule mod_expires.c>
 Header set cache-control: public
 ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
 ExpiresDefault                          "access plus 1 month"

# cache.manifest needs re-reqeusts in FF 3.6 (thx Remy ~Introducing HTML5)
 ExpiresByType text/cache-manifest       "access plus 0 seconds"

# your document html 
 ExpiresByType text/html                  "access"

# rss feed
 ExpiresByType application/rss+xml       "access plus 1 hour"
 ExpiresByType text/xml                          "access plus 1 hour"

# favicon (cannot be renamed)
 ExpiresByType image/vnd.microsoft.icon  "access plus 1 week" 
 ExpiresByType image/x-icon                      "access plus 1 month"

# media: images, video, audio
 ExpiresByType image/png                 "access plus 1 month"
 ExpiresByType image/jpg                 "access plus 1 month"
 ExpiresByType image/jpeg                "access plus 1 month"
 ExpiresByType video/ogg                 "access plus 1 month"
 ExpiresByType audio/ogg                 "access plus 1 month"
 ExpiresByType video/mp4                 "access plus 1 month"

# webfonts
 ExpiresByType font/ttf                  "access plus 1 month"
 ExpiresByType font/woff                 "access plus 1 month"
 ExpiresByType image/svg+xml             "access plus 1 month"

# css and javascript
 ExpiresByType text/css                  "access plus 1 month"
 ExpiresByType application/javascript    "access plus 1 month"
 ExpiresByType text/javascript           "access plus 1 month"
</IfModule>

# Since we're sending far-future expires, we don't need ETags for
# static content.
#   developer.yahoo.com/performance/rules.html#etags
FileETag None

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

перед этим RewriteRule .* index.php/$0 [PT]

 

прописываем условие для posts, чтото вроде(я могу чуть в синтаксие ошибаться):

 

RewriteRule ^/posts.* index2.php/$0 [PT]

 

Добавлено:

выставите там ещё флаг L - чтобы после выполнения правило процесс не продолжил выполнять правило с index.php

Изменено пользователем belial

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Пока искал, оказалось, что сайт в очередной раз переехал обратно на старый движок и данные реврайты уже не нужны. Обидно ((

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Я бы сделал примерно такой индексный файл:

 

if (preg_match('/new-domen.ru/',$_SERVER['HTTP_HOST'])) include_once('index.php');

else include_once('index2.php');

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Идея хорошая, нужно будет при случае потестить.

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гость
Ответить в тему...

×   Вставлено в виде отформатированного текста.   Вставить в виде обычного текста

  Разрешено не более 75 смайлов.

×   Ваша ссылка была автоматически встроена.   Отобразить как ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставить изображения напрямую. Загрузите или вставьте изображения по ссылке.