Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess重写url的一部分,其余部分保持原样_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache htaccess重写url的一部分,其余部分保持原样

Apache htaccess重写url的一部分,其余部分保持原样,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我需要重写url的一部分作为参数,另一部分作为路径。有可能吗?如果有,有人能帮我吗 更具体地说,我有这样一个url: www.mysite/products/producer:some+producer/category:some+category/color:red,blue,yellow 我需要的是 www.mysite/products.php/producer:some+producer/category:some+category/color:red,blue,yellow 根据w

我需要重写url的一部分作为参数,另一部分作为路径。有可能吗?如果有,有人能帮我吗

更具体地说,我有这样一个url:

www.mysite/products/producer:some+producer/category:some+category/color:red,blue,yellow
我需要的是

www.mysite/products.php/producer:some+producer/category:some+category/color:red,blue,yellow
根据
www.mysite/products/
之后的用户查询路径,要使事情变得更有趣,可以缩短或延长

如果我有固定数量的参数,我会写这样的东西

RewriteRule ^products/([a-zA-Z-_0-9]+)/([a-zA-Z-_0-9]+)/?$ products.php/$1/$2 [L]
但随着一些参数的变化,我不知道该怎么办

到目前为止,这是我的全部权限

Options -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite\.pl
RewriteRule ^(.*)$ http://www.mysite.pl/$1 [R=permanent,L]
RewriteRule ^products/(.+)/?$ /products.php/$1 [NE,L]

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
AddDefaultCharset UTF-8
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 month"
Header append Cache-Control "public"
</IfModule>
## EXPIRES CACHING ##
选项-多视图
重新启动发动机
重写cond%{HTTP_HOST}^mysite\.pl
重写规则^(.*)$http://www.mysite.pl/$1[R=永久性,L]
重写规则^products/(.+)/?$/products.php/$1[NE,L]
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript应用程序/javascript
AddDefaultCharset UTF-8
##过期缓存##
过期于
ExpiresByType图像/jpg“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/png“访问加1个月”
ExpiresByType文本/css“访问加1个月”
过期按类型应用程序/pdf“访问加1个月”
ExpiresByType text/x-javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
过期按类型图像/x图标“访问加1年”
ExpiresDefault“访问加1个月”
标头附加缓存控制“公共”
##过期缓存##

您可以使用
+
检查:

RewriteRule ^products/(.+)/?$ /products.php/$1 [NE,L]

将浮动指令放入各自的模块检查:

Options -MultiViews
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^mysite\.pl
    RewriteRule ^(.*)$ http://www.mysite.pl/$1 [R=permanent,L]
    RewriteRule ^products/(.+)/?$ /products.php/$1 [NE,L]
</IfModule>
AddDefaultCharset UTF-8

<IfModule mod_filters.c>
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
    </IfModule>
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType text/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 1 month"
    Header append Cache-Control "public"
</IfModule>
## EXPIRES CACHING ##
选项-多视图
重新启动发动机
重写cond%{HTTP_HOST}^mysite\.pl
重写规则^(.*)$http://www.mysite.pl/$1[R=永久性,L]
重写规则^products/(.+)/?$/products.php/$1[NE,L]
AddDefaultCharset UTF-8
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript应用程序/javascript
##过期缓存##
过期于
ExpiresByType图像/jpg“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/png“访问加1个月”
ExpiresByType文本/css“访问加1个月”
过期按类型应用程序/pdf“访问加1个月”
ExpiresByType text/x-javascript“访问加1个月”
过期按类型应用程序/x-shockwave-flash“访问加1个月”
过期按类型图像/x图标“访问加1年”
ExpiresDefault“访问加1个月”
标头附加缓存控制“公共”
##过期缓存##
方法#1只是改变产品,保持其他一切不变

RewriteRule ^products/$ products.php [NC,L,B,QSA]
方法#2

下面可能是您的htaccess文件的外观

Options -MultiViews
RewriteEngine On

# Prevents directory browsing
Options -Indexes

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

# your 404 page
ErrorDocument 404 /path/to/your/404file.php

RewriteRule ^products/$ products.php [NC,L,B,QSA]
选项-多视图
重新启动发动机
#防止目录浏览
选项-索引
#开始GZIP
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
#结束GZIP
#你的404页
ErrorDocument 404/path/to/your/404file.php
重写规则^products/$products.php[NC、L、B、QSA]

它为我提供了内部服务器Error@krzysztof对不起,我错过了前面的
/
。现在检查还是一样吗result@krzysztof您能否确认htaccess中是否有
选项-多视图
?另外,请检查服务器的错误日志。似乎我没有访问错误日志的权限,或者没有错误日志(从我的透视图来看,目录为空)。虽然你的第一个方法看起来很有前途,但我已经把我的整个htaccess都贴在上面了,它给我的是404error@krzysztof确保您有
选项-MultiViews
enableDiges我已经启用了right选项,我甚至可以说您的第二种方法正在工作-这是处理htaccess中的每个场景所需要的一个问题,也是我一直在寻找的一些更通用的东西,因为我在php方面做得更好。@krzysztof如果这
www.mysite/products/producer:some+producer/category:some+category/color:red、blue、yellow
是您的确切URL,它将不起作用。您需要将其更改为
www.mysite/products/?producer=foo&category=foo&color=foo
@krzysztof基本上方法#1只会将products更改为products.php。其他一切都将保持不变
Options -MultiViews
RewriteEngine On

# Prevents directory browsing
Options -Indexes

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

# your 404 page
ErrorDocument 404 /path/to/your/404file.php

RewriteRule ^products/$ products.php [NC,L,B,QSA]