V
V
Viktor Dotsenko2014-06-17 11:44:26
PHP
Viktor Dotsenko, 2014-06-17 11:44:26

Bitrix: Problem with urlwrite.php?

Good afternoon. There was a question: How to make processing with a slash (/) and without, for pages through urlwrite.php?
For example:
There is a site host.ru/project - it goes perfectly to index.ph
if you type host.ru/project hits 404. It is
necessary that both with a slash (/) at the end and without redirect to normal index.php
Below is the code field = (I don’t know how to make a spoiler!
Processing without a slash comes almost at the very end.

<?
$arUrlRewrite = array(
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/gallery/([0-9]+)#",
    "RULE"	=>	"ID=$1&SECT=$2",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/gallery2.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/gallery+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/gallery.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/sales+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/sales.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([-a-z0-9]+)/gallery/([0-9]+)#",
    "RULE"	=>	"ID=$1&SECT=$2",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/gallery2.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/map+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/map+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/map+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/credit+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/credit.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/credit+([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/credit.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/gallery/([0-9]+)#",
    "RULE"	=>	"ID=$1&SECT=$2",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/gallery2.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/gallery/([0-9]+)#",
    "RULE"	=>	"ID=$1&SECT=$2",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/gallery2.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([-a-z0-9]+)/gallery+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/gallery.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([-a-z0-9]+)/sales+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/sales.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/detail.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/gallery+/*[\s\S]*#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/gallery.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/gallery+/*[\s\S]*#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/gallery.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([-a-z0-9]+)/map+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/credit+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/credit.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/credit+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/credit.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/sales+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/sales.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/sales+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/sales.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/gallery+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/gallery.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/detail.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/detail.php",
  ),	
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)/map+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)/map+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/map.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/sales+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/sales.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects/([-a-z0-9]+)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/house-projects1/detail.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([^\\?]*)([\\s\\S]*)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/detail.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects/([-a-z0-9]+)/map+#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/projects1/map.php",
  ),	
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy/([-a-z0-9]+)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/livecomplex/detail.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses/([-a-z0-9]+)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/townhouses1/detail.php",
  ),

  array(
    "CONDITION"	=>	"#^/press/(\\w+)/([0-9]+)#",
    "RULE"	=>	"SECTION=$1&ID=$2",
    "ID"	=>	"",
    "PATH"	=>	"/press1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/testimonial#",
    "PATH"	=>	"/about1/a_replies.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/partners#",
    "PATH"	=>	"/about1/a_partners.php",
  ),
  array(
    "CONDITION"	=>	"#^/career/vacancy#",
    "PATH"	=>	"/career1/vacancy.php",
  ),
  array(
    "CONDITION"	=>	"#^/house-projects#",
    "PATH"	=>	"/house-projects1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/archieve#",
    "PATH"	=>	"/about1/a_archieve.php",
  ),
  array(
    "CONDITION"	=>	"#^/kaskad-service#",
    "PATH"	=>	"/newpages/otdelka.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/archive#",
    "PATH"	=>	"/about1/a_achieve.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/company#",
    "PATH"	=>	"/about1/a_company.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/leaders#",
    "PATH"	=>	"/about1/a_leaders.php",
  ),
  array(
    "CONDITION"	=>	"#^/news/([0-9]+)#",
    "RULE"	=>	"ID=$1",
    "ID"	=>	"",
    "PATH"	=>	"/news/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/social#",
    "PATH"	=>	"/about1/a_social.php",
  ),
  array(
    "CONDITION"	=>	"#^/about/awards#",
    "PATH"	=>	"/about1/a_awards.php",
  ),
  array(
    "CONDITION"	=>	"#^/press/(\\w+)/#",
    "RULE"	=>	"SECTION=$1",
    "ID"	=>	"",
    "PATH"	=>	"/press1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/career/work#",
    "PATH"	=>	"/career1/work.php",
  ),
  array(
    "CONDITION"	=>	"#^/press/(\\w+)#",
    "RULE"	=>	"SECTION=$1",
    "ID"	=>	"",
    "PATH"	=>	"/press1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/zhilye-kompleksy#",
    "PATH"	=>	"/livecomplex/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/townhouses#",
    "PATH"	=>	"/townhouses1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/contacts#",
    "PATH"	=>	"/contacts1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/projects#",
    "PATH"	=>	"/projects1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/career#",
    "PATH"	=>	"/career1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/press#",
    "PATH"	=>	"/press1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/about#",
    "PATH"	=>	"/about1/index.php",
  ),
  array(
    "CONDITION"	=>	"#^/([^?]*)([\\s\\S]*)#",
    "RULE"	=>	"CODE=$1",
    "ID"	=>	"",
    "PATH"	=>	"/pages1/index.php",
  ),
);

?>

Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Igor, 2014-07-10
@V1rTu

It can be advised to use complex Bitrix components,
there are CComponentEngine::MakeComponentUrlTemplates and CComponentEngine::ParseComponentPath
to help shorten urlwrite.php, it is better to remove the slashes at the end.

D
Dmitry Ioffe, 2014-08-22
@ioffeaod

Solved via .htaccess
Example.
RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ www.site.ru [R=301,L]
RewriteCond %{HTTP_HOST} ^site\ .ru
RewriteRule ^(.*)$ www.site.ru/$1 [R=permanent,L]

K
kompi, 2014-06-17
@kompi

Condition is a regular regular expression: /? or /{0,1}

A
Alexey Emelyanov, 2014-10-17
@babarun

Add to the beginning of the array

array(
    "CONDITION" => "#^/project/(.)*\$#",
    "RULE" => "CODE=\$1",
    "ID" => "",
    "PATH" => "/projects1/index.php",
  ),

And the fact that from the address "/project/..." the script is connected to "/project 1 /..." - is this intended?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question