简单的问题真的。 内部redirect后,原来的“上下文”消失了。 我想知道是否有一个variables或标志,让我检查原来的请求,而不是重写的请求。 伪代码: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule .+ public/$0.html [L] RewriteCond %{WHAT_USER_TYPED} ^public/(.+)\.html RewriteRule .+ – [R=404,L] 在这个例子中,当我键入mywebsite.com/slug ,请求被重写为path public/slug.html 。 现在,发生内部redirect,我的path可能匹配第二个条件public/(.+)\.html ,并返回一个404.这不是我想要的。 所以,我想知道是否有这样的解决scheme。
我运行8-10个基于EC2的Web服务器,所以我的经验是很多小时,但仅限于CentOS; 特别是亚马逊的分销。 我正在使用yum安装Apache,因此获得了Amazon的默认编译Apache。 我想要使用mod_rewrite实现从非www(bare / root)域的规范redirect到www.domain.com的search引擎优化,但是我的.htaccess文件一致地忽略了。 我的故障排除步骤(下面概述)使我相信这是亚马逊构buildApache的特定事件。 testing用例 启动EC2实例,例如Amazon Linux AMI 2013.03.1 SSH到服务器 运行命令: $ sudo yum install httpd $ sudo apachectl start $ sudo vi /etc/httpd/conf/httpd.conf $ sudo apachectl restart $ sudo vi /var/www/html/.htaccess 在httpd.conf中,我更改了以下内容,在DOCROOT部分/范围中: AllowOverride All 在.htaccess中,补充说: (编辑,我后来添加了RewriteEngine On ) RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] RewriteRule ^/(.*) http://www.domain.com/$1 [R=301,L] .htaccess上的权限是正确的,AFAI可以告诉: $ ls -al /var/www/html/.htaccess […]
我尝试在具有shell访问权的共享服务器上设置Trac,SW是Trac 1.0.1,Python 2.6.6,Apache 2.2.15,带有mod_fcgid和mod_suexec。 我已经按照我的主机的wiki的说明设置了它, https: //uberspace.de/dokuwiki/cool:trac。 唯一的区别是我的TRAC_ENV目录位于子目录中,而不是直接在我的家里(即〜/ path / to / trac,而不是〜/ trac)。 (我在DocRoot中将trac.fcgi重命名为foo-trac.fcgi,如下所示,但我也尝试将其重命名为trac.fcgi。) 正如在那里写的,我从TRAC_ENV / deploy / cgi-bin /复制了trac.fcgi(也尝试了trac.cgi)到$ DocRoot / foo / foo-trac.fcgi并添加 Options +ExecCGI AddHandler fcgid-script .fcgi # also tried "AddHandler cgi-script .cgi" RewriteEngine On RewriteBase /foo RewriteRule ^$ foo-trac.fcgi [L] # also tried foo-trac.cgi RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d […]
我的设置: Ubuntu 13.04 Apache / 2.2.22(Ubuntu) PHP 5.4.9-4ubuntu2.2 – $ ls /etc/apache2/mods-enabled/*.load alias.load auth_basic.load authn_file.load authz_default.load authz_groupfile.load authz_host.load authz_user.load autoindex.load cgi.load deflate.load dir.load env.load expires.load mime.load negotiation.load php5.load reqtimeout.load rewrite.load setenvif.load status.load userdir.load 使用redirect到/home/*/www mod_userdir 在/home/*/www/styles有一个.htaccess文件,其中包含以下指令: RewriteEngine On RewriteRule (styles-files/.+)\.(\d{10})\.(\w{2,4})$ $1.$3 [L] 现在这里是令人困惑的部分(个人信息蒙上了阴影) 加载http://localhost/~***/styles/styles-files/css/jquery.qtip.css可以正常工作(文件显示在浏览器中) 加载http://localhost/~***/styles/styles-files/css/jquery.qtip.1376640525.css给我404错误,但消息说“/ home / *** / www / styles / styles-文件/ css […]
嗨,我已经写了一些重写,但从我可以告诉从日志看来,规则继续执行,所以,虽然正确的结果是在执行中,但最终的重写是不正确的。 理想情况下,我需要使用[END]标志,但是我不能升级Apache 2.2的服务器软件,所以我将不得不解决这个问题。 我试图把“/ wedding?url = emily-and-john-2013”改写为“/ wedding / emily-and-john-2013”。 因为我使用CodeIgniter,我首先需要将“index.php / wedding / …”改写为“/ wedding / …”。 这是我迄今为止的规则。 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #Checks to see if the user is attempting to access a valid file, #such as an image or css document, if this isn't true it sends the #request to index.php […]
按照预期 ,在htaccess中重写下面这个HTTPS请求不会被重写: https://example.com/system/anything 不重写 http://example.com/system/anything 但是,意外的是,这个HTTPS请求被重写了: https://example.com/preview/anything 被重写 http://example.com/index.php/preview/anything 为什么是这样? 一些其他的事实/意见: /system/是服务器上的实际path。 但是/preview/不是一个真正的path – 这是一个在CMS中有意义的URL段,例如,/ /index.php/preview/anything /preview/anything是CMS如何获取/preview/anything URL的请求。 其他非系统的URL会正确地重写(从HTTPS到HTTP),并正确传递给index.php。 例如, https://example.com/real 被重写 http://example.com/real 这是一整套规则: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Force HTTPS for System URLs RewriteCond %{REQUEST_URI} ^/system(.*)$ [NC] RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ "https://example.com/$1" [R=301,L] # Force HTTP for Other URLs, but not: […]
我想dynamic代理子文件夹到另一个主机上的子域。 例如,我有以下反向代理设置为单个子文件夹到子域: ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /app1/ http://app1.myotherserver.tld/ ProxyPassReverse /app1/ http://app1.myotherserver.tld/ 上述工作正常(除了尾随的“/”问题)。 但是,我需要添加另外10个,就像它,app2,app3,app4等…也许在未来更多。 添加每一个显然是没有意义的。 使用http://httpd.apache.org/docs/current/rewrite/proxy.html的页面作为参考,我这样做: RewriteRule ^/(.*)/$ http://$1.myotherserver.tld/ [P] RewriteRule ^/(.*)/(.*)$ http://$1.myotherserver.tld/$2 [P] ProxyPassReverse /$1/ http://$1.myotherserver.tld/ 这样的作品,但我现有的子文件夹被拉入该规则,我仍然有问题的尾随“/”。 我尝试添加“?” 遵循第一条规则,但是这打破了一切: RewriteRule ^/(.*)?/$ http://$1.myotherserver.tld/ [P] 我如何使“http; // www.mywebserver.tld / app2”这样的东西工作,但仍然允许这些有效的URL仍然工作? http://www.mywebserver.tld/style.css http://www.mywebserver.tld/images/title.png http://www.mywebserver.tld/existingsubfolder http://www.mywebserver.tld/existingsubfolder/page.php
我需要重写几个url,如果这些url没有结束某些单词。 例如,我需要重写下面的url /category1/subcategory1/aproduct-url-title to /category1/fixedword/aproduct-url-title 重写不应该发生在下面的url上,因为这些链接以某些特定的词结束(view-all,p10,p20,p30,从低到高,从高到低) – /category1/subcategory1/view-all /category1/subcategory1/p10 /category1/subcategory1/p20 /category1/subcategory1/low-to-high /category1/subcategory1/high-to-low 我试着用下面的规则没有成功 – RewriteRule ^(category1|category2)\/(.*)\/(!p[0-9]+|view-all|low-to-high|high-to-low)$ /$1/fixedword/$3 我也试过以下规则 – RewriteCond %{REQUEST_URI} !(p[0-9]+|view-all|low-to-high|high-to-low)$ RewriteRule ^(category1|category2)\/(.*)\/(.*)$ /$1/fixedword/$3 感谢你的帮助。 谢谢
我有domain.com和sub.domain.com指向相同的服务器,我使用mod_rewrite重写sub.domain.com到sub子目录的URL。 我在文档根目录中有以下.htaccess文件: DirectoryIndex index.html index.php # Prevent infinite rewrite loop. RewriteCond %{ENV:REDIRECT_STATUS} ^$ # Send all requests addressing sub.domain.com… RewriteCond %{HTTP_HOST} =sub.domain.com [NC] # …to the /sub directory. RewriteRule ^ /sub%{REQUEST_URI} [QSA] 在sub我有index.php和没有index.html ,但请求http://sub.domain.com似乎完全忽略index.php并返回404。如果我有index.html那里,但是,它是提供服务。 我能得到index.php服务的唯一方法就是设置 DirectoryIndex index.php 但是这不是我想为整个网站做的事情。 奇怪的是,文档根以外的URL显示正常的DirectoryIndex行为。 例如, http://sub.domain.com/search //sub.domain.com/search试图在返回404之前查找sub/search/index.html然后是sub/search/index.php 。 如果我从父域http://domain.com/sub查询sub ,我能够看到index.php ,这让我完全傻眼的问题。 我会包括Apache错误日志,但我使用共享主机,并没有办法增加日志冗长。 另外,我无法在本地重现此错误。 networking托pipe服务器使用Apache 2.4.3,我的本地服务器是Apache 2.4.9。
在试图重写 site-search.html?searchword=search%20term 如 advanced-search#q=search%20term 我总是以advanced-search#q=%3Fsearchword%3search%20term %3Fsearchword%3部分被神秘地添加到正好在search词之前的生成的URL中。 我现在的规则如下: RewriteCond %{REQUEST_URI} ^/site-search\.html$ RewriteCond %{QUERY_STRING} ^searchword=(.*)$ RewriteRule ^(.*)$ http://www.example.com/advanced-search#q=%1 [R=301,L,NE] 值得一提的是,在“q =”之后,我没有什么不同。 无论如何也会发生同样的错误或轻微的变化。