簡體   English   中英

如何使用.htaccess將斜杠作為語言參數重定向到我的網站頁面

[英]How do I redirect to a page of my site taking the trailing slash as the language parameter using .htaccess

我有此規則無法正確重定向:

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]

內部不會收到參數頁面,因此該站點將顯示主頁。 我不確定此規則是否錯誤,或者是否與其他運行正常的規則相沖突,或者是否有訂單問題。

非常感謝所有幫助。 提前致謝。

以下是我網站根目錄上的完整htaccess文件,以備您查看。

Options +FollowSymlinks
RewriteEngine on

DirectoryIndex index.php

#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /es$ public/index.php?lang=es [L]

#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule /en$ public/index.php?lang=en [L]

#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]

#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule page-(.*)$ public/index.php?page=$1 [L]

#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

好的,發現問題似乎確實存在,這確實是一個訂單問題,這似乎可行,希望這可以幫助遇到相同問題的人

Options +FollowSymlinks
RewriteEngine on

DirectoryIndex index.php

#Adds www to the domain
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]

#redirect from www.mysite.com/page-NAME/es to www.mysite.com/public/index.php?page=NAME/es
RewriteRule page-(.*)/es$ public/index.php?page=$1&lang=es [L]

#redirect from www.mysite.com/page-NAME to www.mysite.com/public/index.php?page=NAME
RewriteRule page-(.*)$ public/index.php?page=$1 [L]


#redirect from www.mysite.com/es to www.mysite.com/public/index.php?lang=es
RewriteRule /es public/index.php?lang=es [L]

#redirect from www.mysite.com/en to www.mysite.com/public/index.php?lang=en
RewriteRule /en public/index.php?lang=en [L]

#redirect from www.mysite.com/ to www.mysite.com/public/index.php
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(/)?$ public/index.php [L]


#redirect from www.mysite.com/ to www.mysite.com/public/
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/$1 [L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM