将.htaccess更改为重定向到特定URL

将.htaccess更改为重定向到特定URL,.htaccess,shopware,.htaccess,Shopware,当有人在我的店铺中打开一个不存在的站点时,我想将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

当有人在我的店铺中打开一个不存在的站点时,我想将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

重新启动发动机
#新基地/商店用品/
重写规则shopware.dll shopware.php
重写规则文件/文档/*引擎[NC,L]
重写规则后端/媒体/(*)媒体/$1[NC,L]
重写cond%{REQUEST_URI}!(\/(引擎文件模板)\/)
重写cond%{REQUEST_URI}!(\/media\/(存档|横幅|图像|音乐| pdf |未知|视频)\/)
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$shopware.php[PT,L,QSA]
#暂存规则开始
#SetEnvIf主机“staging.test.shopware.in”ENV=staging
DirectoryIndex.html
DirectoryIndex.php
DirectoryIndex shopware.php
#禁用配置的下载
全盘否定
#启用gzip压缩
#由于在windows上的google chrome中加载问题,禁用iconset上的压缩
setEnvifLocase请求\u URI图标集。css$no gzip不变
AddOutputFilterByType DEFLATE text/html text/xml text/plain text/css text/javascript application/json
过期于
ExpiresDefault“访问加1个月”
FileTag无
标头附加缓存控制“公共”
标题未设置ETag
#禁用自动目录索引
选项-索引
选项-多视图
#php_值内存_限制128M
#php_值最大执行时间120
#php\u值上传\u最大\u文件大小20M
php_flag phar.readonly关闭
php_标志魔术_引号_gpc关闭
php_标志session.auto_启动
关闭php_标志suhosin.session.cryptua
php_标志zend.ze1_兼容性_模式关闭
#AddType x-mapp-php5.php
#AddHandler x-mapp-php5.php

我在谷歌上搜索了很多东西,尝试了一些东西,但没有一个对我有用。

我可能会在这里使用
ErrorDocument
(前提是当你说“不存在的商店”时所描述的状态会导致HTTP状态为404。例如:

ErrorDocument 404 /path/to/errorPage.php
这里面有更多的信息

如果您希望基于条件进行重定向(在本例中,例如不存在商店),那么您还可以在php中尝试使用
header()
()进行重定向,特别是控制用户访问哪个页面的部分


请记住,一旦开始向浏览器输出,就不能使用
header()
,因为它将尝试发送原始HTTP头,如果脚本已经向浏览器回显了某些内容,则无法执行此操作。

我可能会在此处使用
ErrorDocument
(前提是当您说“不存在的商店”时所描述的状态导致HTTP状态为404。例如:

ErrorDocument 404 /path/to/errorPage.php
这里面有更多的信息

如果您希望基于条件进行重定向(在本例中,例如不存在商店),那么您还可以在php中尝试使用
header()
()进行重定向,特别是控制用户访问哪个页面的部分


请记住,您不能使用
header()
一旦开始向浏览器输出,因为它将尝试发送原始HTTP头,如果您的脚本已经向浏览器回送了内容,则无法执行此操作。

要实现问题中描述的所需行为,您必须安装一个Shopware插件,让您指定一个登录页,在找不到页面(商店内发生HTTP 404错误)

幸运的是,有一些插件可供您使用。您可以在Shopware社区商店中找到它们,搜索术语“404”:

不幸的是,通过向.htaccess文件中添加规则无法实现所需的行为

由于Shopware URL是虚拟的,因此默认.htaccess文件(您已发布)中的重写规则将所有请求定向到Shopware:

RewriteRule ^(.*)$ shopware.php [PT,L,QSA]
之后,Shopware必须确定URL是否正确,页面是否找到。如果找不到所需的URL,Shopware将发送正确的404状态代码,但会显示起始页


由于只有Shopware可以确定URL是否在其系统中找到,因此此时.htaccess中的Apache重写规则将不再有效。Apache此时也不能在PHP应用程序之后使用ErrorDocument(在本例中为Shopware)已处理请求。

要实现问题所述的预期行为,您必须安装Shopware插件,让您指定一个登录页,当找不到页面时将显示该登录页(商店内发生HTTP 404错误)

幸运的是,有一些插件可供您使用。您可以在Shopware社区商店中找到它们,搜索术语“404”:

不幸的是,通过向.htaccess文件中添加规则无法实现所需的行为

由于Shopware URL是虚拟的,因此默认.htaccess文件(您已发布)中的重写规则将所有请求定向到Shopware:

RewriteRule ^(.*)$ shopware.php [PT,L,QSA]
之后,Shopware必须确定URL是否正确,页面是否找到。如果找不到所需的URL,Shopware将发送正确的404状态代码,但会显示起始页


由于只有Shopware可以确定URL是否在其系统中找到,因此此时.htaccess中的Apache重写规则将不再有效。Apache此时也不能在PHP应用程序之后使用ErrorDocument(在本例中为Shopware)已处理请求。

谢谢您的回答,我指的是我的店铺中不存在的网站,例如“shop.com/sitethattnotexist.html”这应该指向shop.com/landingpage.html。在htaccess的哪个位置我应该粘贴此代码吗?如果您希望尝试访问不存在的商店以重定向到主页/登录页,那么我不确定使用.htaccess在技术上是否是最合理的方法。在逻辑的某个地方,决定了使用哪个h特定页面