簡體   English   中英

更改.htaccess以重定向到特定的URL

[英]Change .htaccess to redirect to a specific URL

當有人在我的商店中打開一個不存在的網站時,我想更改我的shopware .htaccess文件以重定向到特定的URL。

這是我的.htaccess

    <IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /shopware/

RewriteRule shopware.dll shopware.php
RewriteRule files/documents/.* engine [NC,L]
RewriteRule backend/media/(.*) media/$1 [NC,L]

RewriteCond %{REQUEST_URI} !(\/(engine|files|templates)\/)
RewriteCond %{REQUEST_URI} !(\/media\/(archive|banner|image|music|pdf|unknown|video)\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ shopware.php [PT,L,QSA]
</IfModule>

# Staging-Rules start
#SetEnvIf Host "staging.test.shopware.in" ENV=staging

DirectoryIndex index.html
DirectoryIndex index.php
DirectoryIndex shopware.php

# Disables download of configuration
<Files ~ "\.(tpl|yml|ini)$">
Deny from all
</Files>

# Enable gzip compression
<IfModule mod_deflate.c>
# disable compression on iconset due to loading problems in google chrome on windows
SetEnvIfNoCase Request_URI icon-set.css$ no-gzip dont-vary

AddOutputFilterByType DEFLATE text/html text/xml text/plain text/css text/javascript application/json
</IfModule>

<IfModule mod_expires.c>
<Files ~ "\.(jpe?g|png|gif|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 month"
FileETag None
<IfModule mod_headers.c>
Header append Cache-Control "public"
Header unset ETag
</IfModule>
</Files>
</IfModule>

# Disables auto directory index
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>

<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>

<IfModule mod_php5.c>
# php_value memory_limit 128M
# php_value max_execution_time 120
# php_value upload_max_filesize 20M
php_flag phar.readonly off
php_flag magic_quotes_gpc off
php_flag session.auto_start off
php_flag suhosin.session.cryptua off
php_flag zend.ze1_compatibility_mode off
</IfModule>

# AddType x-mapp-php5 .php
# AddHandler x-mapp-php5 .php

我在Google上搜索了很多東西,並嘗試了一些方法,但對我來說沒有什么用。

我可能會在這里使用ErrorDocument (假設您說“不存在的商店”時所描述的狀態導致HTTP狀態為404。例如:

ErrorDocument 404 /path/to/errorPage.php

apache的文檔中有關於此的更多信息。

如果您想基於條件進行重定向(在這種情況下,例如商店不存在),那么您也可以嘗試在php中使用header()文檔在此處 )進行重定向-具體來說就是例如,用戶被帶到哪個頁面。

請記住,一旦開始向瀏覽器輸出,就不能使用header() ,因為它將嘗試發送原始的HTTP標頭,如果您的腳本已經向瀏覽器回顯了某些內容,則無法執行此操作。

為了實現您的問題所描述的理想行為,您將必須安裝Shopware插件,讓您指定登錄頁面,該登錄頁面將在找不到頁面時顯示(商店內發生HTTP 404錯誤)。

幸運的是,您可以使用一些插件。 您可以在Shopware社區商店中找到它們,並搜索術語“ 404”: http ://store.shopware.com/search?sSearch=404

不幸的是,無法通過在.htaccess文件中添加規則來實現所需的行為。

由於Shopware URL是虛擬的,因此默認的.htaccess文件(您已過帳)中的重寫規則會將所有請求定向到Shopware:

RewriteRule ^(.*)$ shopware.php [PT,L,QSA]

之后必須確定Shopware,URL是否正確並找到頁面。 如果找不到所需的URL,Shopware將發送正確的404狀態代碼,但顯示起始頁。

由於只有Shopware可以確定,如果無法在其系統中找到URL,則此時.htaccess中的Apache重寫規則將不再起作用。 PHP應用程序(在本例中為Shopware)處理了請求之后,Apache此時無法使用ErrorDocument。

暫無
暫無

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

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