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

时间:2015-06-09 15:45:07

标签: .htaccess shopware

当有人在我的商店中打开一个不存在的网站时,我想更改我的商品.htaccess文件以重定向到特定网址。

这是我的.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上搜索了很多东西并尝试过一些东西,但对我来说没什么用。

1 个答案:

答案 0 :(得分:0)

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

ErrorDocument 404 /path/to/errorPage.php

apache's documentation内有关于此的更多信息。

如果您想根据条件进行重定向(在这种情况下,例如商店不存在),那么您也可以尝试使用header()documentation is here)重定向php - 特别是管理用户被带到哪个页面的部分。

请记住,一旦输出到浏览器开始就不能使用header(),因为它会尝试发送原始HTTP标头,如果您的脚本已经回显,则无法完成浏览器的东西。