繁体   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