我没有编辑.htaccess的经验 我想 redirect非www到www。 删除.php扩展名 设置一个自定义的404页面 我设法做到这一点(寻找在networking和serverfault.com解决scheme),但现在看来,我的旧的redirect301扩展名为.php不再工作: redirect301 /download.php /features.php 我怎么能解决它? 谢谢! RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] Options +FollowSymlinks -MultiViews RewriteEngine on RewriteCond %{THE_REQUEST} ^GET\s.+\.php [NC] RewriteRule ^(.+)\.php$ /$1 [NE,R=301,L,NC] RewriteCond %{REQUEST_URI} !\.php$ [NC] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule . %{REQUEST_URI}.php [L] Options +FollowSymlinks ErrorDocument 404 /404 RewriteEngine on
我终于写在这里,因为我非常努力地对抗apache,SSL / TLS和客户端证书authentication,应该使用证书的序列号来限制访问特定的API调用。 更好地解释一些细节: 用户必须能够访问: https:// {host} / apiv3xx / s?testing没有任何问题和限制,但对于以下url: https:// {host} / apiv3xx / x?action = login&user = blablabla为了执行呼叫,需要客户端证书。 我以为实施以下解决scheme: <Location /apiv3xx> SetEnv api 1 SSLOptions +StdEnvVars -ExportCertData SSLVerifyClient optional SSLVerifyDepth 10 </Location> 另外还有一些重写规则来控制逻辑: RewriteCond %{REQUEST_URI} ^/apiv3xx/ [NC] RewriteCond %{QUERY_STRING} action=log([^&]*)?(?=&|$) [NC,OR] RewriteCond %{QUERY_STRING} action=adm([^&]*)?(?=&|$) [NC,OR] RewriteCond %{QUERY_STRING} action=ctc([^&]*)?(?=&|$) [NC] RewriteCond %{SSL:SSL_CLIENT_M_SERIAL} !(01000000000140AAD72ACCXXXXXX|02000000000140BAD37F1XXXXXXX) […]
背景: 为了减less包含wordpress安装的git repos的回购大小,我们从回购中删除静态资产。 大部分工作已经完成,但我有一个障碍。 我已将资产重新定位到S3存储桶,并使用.htaccess RedirectPermanent,以便将本地媒体的请求redirect到s3存储桶。 这是很好的pipe理所有在一个新的地方的现有资产,而无需修改wp数据库。 但是,对于新添加的资产,我们使用“Amazon S3和Cloudfront”插件将它们上传到服务器后自动移动到同一个S3存储桶。 然而,为了工作,我需要使用THE_REQUEST将RedirectPermanent改为RewriteRule,这样只有媒体的GET请求才会指向S3存储桶。 这是因为“Amazon S3和Cloudfront”插件需要允许将文件作为caching本地上传,并从中推送到S3存储桶。 以下是我们目前在.htaccess中的内容: RedirectPermanent /media https://s3-us-west-2.amazonaws.com/bucket/media # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteRule ^assets/(.*) /wp-content/themes/theme/assets/$1 [QSA,L] RewriteRule ^plugins/(.*) /wp-content/plugins/$1 [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 我对Apache Rewrite规则和条件不是很满意,在格式化比赛正则expression式方面我特别弱,而且我的专业水平和实际编写重写规则的能力也会更好。 我已经阅读了一些关于如何使用THE_REQUEST的在线示例,我知道我需要这样的东西: #there's definitely more that […]
我对nginx很新,但是以前有过apacheredirect的经验。 我将一个子域名转换为一个子文件夹,并需要一些帮助,让我的重写规则正确的交换机。 子域托pipe在apache服务器上,新的子目录托pipe在我的新nginx服务器上。 下面是包含我所需的redirect的工作htaccess文件: Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTP_HOST} ^france-property\.frenchentree\.com$ [NC] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^for-sale/(.*)$ http://www.frenchentree.com/property-for-sale/search/$1? [R=301,NE,NC,L] RewriteCond %{HTTP_HOST} ^france-property\.frenchentree\.com$ [NC] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^for-sale$ http://www.frenchentree.com/property-for-sale/search? [R=301,NE,NC,L] RewriteCond %{HTTP_HOST} ^france-property\.frenchentree\.com$ [NC] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^for-sale-details(.*) http://www.frenchentree.com/property-for-sale/details$1? [R=301,NE,NC,L] RewriteCond %{HTTP_HOST} ^france-property\.frenchentree\.com$ [NC] RewriteCond %{QUERY_STRING} ^$ RewriteRule ^buyer-registration(.*)$ http://www.frenchentree.com/property-for-sale/buyer-registration? [R=301,NE,NC,L] RewriteCond %{HTTP_HOST} ^france-property\.frenchentree\.com$ […]
我有两个应用程序在同一台服务器上,并使用Apache重写规则redirect: www请求非www http请求https 除了一种情况外,一切正常, 请求www.test2.test.euredirect到https://www.test1.com内容 我怎样才能正确识别它? 在域test1.comconfiguration文件中重写 : ServerName test1.com RewriteCond%{HTTP_HOST} ^ www.test1.com $ [NC] RewriteRule ^(。*)$ https://www.test1.com/ $ 1 [R = 301] RewriteCond%{SERVER_PORT}!^ 443 $ RewriteRule ^。* $ https://%{SERVER_NAME}%{REQUEST_URI} 在域test2.test.euconfiguration文件中重写 : ServerName test2.test.eu RewriteCond%{HTTP_HOST} ^ www.test2.test.eu $ [NC] RewriteRule ^(。*)$ https://www.test2.test.eu/ $ 1 [R = 301] RewriteCond%{SERVER_PORT}!^ 443 $ RewriteRule ^。* $ https://%{SERVER_NAME}%{REQUEST_URI} 任何build议非常赞赏。 […]
我有一个基于Plone的站点,运行在Apache 2.4后面,可能会更好一些。 一个想法是让Apache服务于内容的静态部分,防止它们被重写为Plone进程,就像通常做的那样: RewriteEngine On RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/Plone/VirtualHostRoot/$1 [L,P 那些静态内容并不在同一个地方。 但是Plone提供了一个标准的资源目录命名方式, 例如,我的产品的“浏览器” mybrowser可以有一个文件系统目录static : /my/plone/root/Products/myproduct/mybrowser/static/ 它将作为/++resource++mybrowser-static 。 让Plone提供静态文件没有太大意义,所以我想阻止某些请求被重写,而是直接提供服务。 这是我试过的: # in Plone: /++resource++mybrowser-static <Directory /my/plone/root/Products/myproduct/mybrowser/static> Options All AllowOverride All Require all granted </Directory> Alias /static /my/plone/root/Products/myproduct/mybrowser/static Alias /++resource++mybrowser-static /my/plone/root/Products/myproduct/mybrowser/static LogLevel alert rewrite:trace3 alias:trace3 … RewriteCond %{REQUEST_URI} !^/++resource++mybrowser-static RewriteCond %{REQUEST_URI} !^/static/ RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/%{HTTP_HOST}:80/Plone/VirtualHostRoot/$1 [L,P] 因此,我目前有两个别名, […]
我在我的服务器上托pipe了多个网站,所有这些网站都共享一个htaccess的相同代码库。 我需要这样的东西。 如果(域名!= example.com)redirect到example.com 如果有任何处理这个从htaccess的方式 使用以下但仍然不工作 RewriteCond !^(.*)$ https://example1.com/$1 [NC] RewriteRule ^(.*)$ https://example2.com/$1 [R=301,NC,L]
我有两个域,其内容在同一个文件目录中: http://www.alpha.com/ DIR: /var/www/alpha.com/ 和 http://www.beta.com/ DIR: /var/www/beta.com/ 我想要做以下事情: 当用户去 http://www.alpha.com/beta/ 他应该看到的内容 http://www.beta.com 并通过去例如 http://www.alpha.com/beta/index.php?a=3&b=2 他应该看到的内容 http://www.beta.com/index.php?a=3&b=2 等等。 我如何使用htaccesspipe理? 我应该在哪个目录中放置? 我想过: RewriteEngine On RewriteRule ^\.htaccess$ – [F] RewriteCond %{REQUEST_URI} ^/beta/(var1)$ RewriteRule ^.*$ http://beta.com/%1 但它不起作用。 而我在正则expression式方面不太好。 谢谢你的每一个答案!
我正在使用这个重写规则redirect example.com/abc?id=learn-more —-> http://example.com/abc?id=learnmore rewrite ^/abc?id=learn-More http://example.com/abc?id=learnMore permanent 但它不工作! 它正在redirect到 example.com/abc?id=learn-more(learn-more不会转换为learnmore)。 如何做到这一点?
我有一个不在我的文档根目录的static文件夹。 我想redirect所有不存在于文档根目录但存在于静态文件夹中的文件。 (所以如果同一文件在两个地方,那么不在静态的文件将首先被提供。)我该怎么做? 以下不起作用: DocumentRoot /srv/app/client/build/ Alias / /srv/app/client/static RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/ RewriteRule ^(.*)$ /$1 <Location /> Order allow,deny Allow from all </Location>