拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 htaccess将POST讯息重定向到子档案夹中的php档案

htaccess将POST讯息重定向到子档案夹中的php档案

白鹭 - 2022-01-26 2115 0 0

我希望有人可以帮助我在共享托管方案中纠正我的 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) 的部分输出

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',
)

uj5u.com热心网友回复:

问题在于

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 的那部分是可选的以匹配此规则。

uj5u.com热心网友回复:

根据 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 提到这种根据收到的反馈发布问题的可行解决方案的方式

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *