簡體   English   中英

htaccess 將 POST 消息重定向到子文件夾中的 php 文件

[英]htaccess redirect POST message to php file in subfolder

我希望有人可以幫助我在共享主機方案中糾正我的 htaccess 問題,所以我無法訪問 httpd.conf。 我正在嘗試將 POST 重定向到 /process-dev.php 到正確子文件夾中的文件,如下所示,但是我的 POST 被重定向到 index.php
POST來自網頁本身(實際域替換為subdomain1.com)https:://www.subdomain1.com。

/
|- .htaccess
|- css
|- clientscripts
|- php
|- site
    |- subdomain1.com
        |- language
            |- default
                |- process-dev.php
                |- index.php

我的 htaccess 文件

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

Options +FollowSymlinks
Options -Indexes

RewriteEngine on

# Enforce SSL
RewriteCond %{HTTPS} !=on
# Handle non-www URLs
RewriteCond %{HTTP_HOST} ^subdomain1\.com [NC,OR]
# Handle www URLs
RewriteCond %{HTTP_HOST} ^www\.subdomain1\.com [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/?(process-dev|post-file-dev|post-image-dev)?$ [NC]
RewriteRule ^.*$ site/subdomain1.com/language/default/$1.php [L,QSA]

# Redirect all to the Application if not done already
RewriteCond %{REQUEST_URI} !^/?site/subdomain1\.com/language/default/index\.php [NC]

# or if request is a real file
RewriteCond %{REQUEST_FILENAME} !-f

# or if request is a real directory but not the root directory
RewriteCond %{REQUEST_URI} ^/?$ [OR]
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite the rest to the index.php file in your public folder
RewriteRule ^.*$ site/subdomain1.com/language/default/index.php [NC,L]

print($_server) 的部分 output

map(
'ONECOM_DOMAIN_NAME'=>'subdomain1.com',
'ONECOM_DOMAIN_ROOT'=>'/customers/6/6/d/subdomain1.com/',
'SCRIPT_NAME'=>'/site/subdomain1.com/language/default/index.php',
'REQUEST_URI'=>'/process-dev.php',
'QUERY_STRING'=>'',
'REQUEST_METHOD'=>'POST',
'SERVER_PROTOCOL'=>'HTTP/1.1',
'REDIRECT_URL'=>'/process-dev.php',
'SCRIPT_FILENAME'=>'/customers/6/6/d/subdomain1.com/httpd.www/site/subdomain1.com/language/default/index.php',
'SERVER_NAME'=>'subdomain1.com',
'HTTP_REFERER'=>'https://subdomain1.com/',
'HTTP_ORIGIN'=>'https://subdomain1.com',
'HTTP_SCHEME'=>'https',
'HTTP_HOST'=>'subdomain1.com',
'HTTPS'=>'on',
'ONECOM_TMPDIR'=>'/customers/6/6/d/subdomain1.com//tmp',
'DOMAIN_NAME'=>'subdomain1.com',
'ONECOM_DOCUMENT_ROOT'=>'/customers/6/6/d/subdomain1.com/httpd.www',
'DOCUMENT_ROOT'=>'/customers/6/6/d/subdomain1.com/httpd.www',
'REDIRECT_STATUS'=>'200',
'REDIRECT_HTTPS'=>'on',
'REDIRECT_ONECOM_TMPDIR'=>'/customers/6/6/d/subdomain1.com//tmp',
'REDIRECT_ONECOM_DOMAIN_ROOT'=>'/customers/6/6/d/subdomain1.com/',
'REDIRECT_ONECOM_DOMAIN_NAME'=>'subdomain1.com',
'REDIRECT_DOMAIN_NAME'=>'subdomain1.com',
'REDIRECT_ONECOM_DOCUMENT_ROOT'=>'/customers/6/6/d/subdomain1.com/httpd.www',
'REDIRECT_DOCUMENT_ROOT'=>'/customers/6/6/d/subdomain1.com/httpd.www',
'PHP_SELF'=>'/site/subdomain1.com/language/default/index.php',
)

根據 Raxi 的建議,我讓它與這個變化一起工作

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/?(process-dev\.php|post-file-dev\.php|post-image-dev\.php)$ [NC]
RewriteRule ^.*$ site/subdomain1.com/language/default/%1 [L,QSA]

感謝 MrWhite 提到這種方式,根據收到的反饋發布問題的有效解決方案

問題在於

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/?(process-dev|post-file-dev|post-image-dev)?$ [NC]
RewriteRule ^.*$ site/subdomain1.com/language/default/$1.php [L,QSA]

您正在使用$1但 RewriteRule ( ^.*$ ) 中沒有分組模式,您需要使用%1來引用早期RewriteCond中的組。

另外,我不確定您是否真的願意放第二個? 在 RewriteCond 模式中? 我對此表示懷疑,因為該組是可選的,條件將匹配任何可能的 uri。

最有可能你想刪除它? ; 但是如果你真的想匹配任何 POST 請求,那么你必須采取一些特殊的考慮,這樣你就不會最終重寫為/.php (空文件名)。

暫無
暫無

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

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