我希望有人可以幫助我在共享托管方案中糾正我的 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 提到這種根據收到的反饋發布問題的可行解決方案的方式
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389460.html
