mod-rewrite

Using mod_rewrite to 301 to SERVER_NAME

佐手、 提交于 2019-12-22 11:27:53
问题 I have many ServerAlias'es in my Apache vhost and I want all domains that aren't the ServerName to be 301'ed to the ServerName. This is not working: RewriteCond %{HTTP_HOST} !%{SERVER_NAME} [NC] RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,QSA,L] This does work: RewriteCond %{HTTP_HOST} !www.some-domain.com [NC] RewriteRule ^(.*)$ http://%{SERVER_NAME}/$1 [R=301,QSA,L] Can I do this without hard coding the domain name? 回答1: Environment variables are only expanded on the left hand side

Redirect all non-www to www for both http and https with .htaccess

送分小仙女□ 提交于 2019-12-22 10:57:07
问题 I want to redirect all non-www to www - if the request is through http it should redirect to http://www.domain.com, if the request is through https then direct to https://www.domain.com I have tried the following in my .htaccess, but it redirects everything to https RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301 I have used this code and it's resolving

Why $_POST is empty when using [QSA] in .htaccess?

允我心安 提交于 2019-12-22 10:51:02
问题 I've got the following in .htaccess: RewriteCond %{REQUEST_URI} !app/index\.php$ RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L] Everyting works great but result URLs have empty $_POST. I'm 100% sure that it's mod_rewrite bug, not HTML or PHP because when I change [QSA,L] to [L] it works great. But I really need QSA. It happens at about 30% hostings so this may be some Apache config option. 回答1: What about modifying your rule in this way. Does it change anything? RewriteRule ^(.*)\.htm$

Apache Alias “Best guess” filename

醉酒当歌 提交于 2019-12-22 10:49:51
问题 Using Apache and mod_rewrite I can rewrite a complex request to a simple filename, eg: RewriteRule ^shortcut/(.*)$ /long/way/around/$1 Can this work in reverse? I want a simple request to be rewritten to an unknown file, but I can identify which file should be served by a unique ID number prefixed to it's filename. I want Apache to "guess" using a regular expression which file to serve based on the ID. For example: GET /img/29281.jpg Directory of /img/: ... 29280-filename-here.jpg 29281-other

.htaccess redirect + rewrite: Prefix uri with language code while keeping initial uri

£可爱£侵袭症+ 提交于 2019-12-22 10:47:11
问题 I am trying to rewrite/redirect incoming requests so that they will always be prefixed by a language code but would like to keep the originally requested path: example.org/de/ -> rewrite to example.org?lang=de example.org -> redirect to example.org/de/ which will then be rewritten to example.org?lang=de example.org/en/ -> rewrite to example.org?lang=en example.org/foo/bar -> redirect to example.org/de/foo/bar wich will then be rewritten to example.org/foo/bar?lang=de These were my thoughts on

mod_rewrite, can't rewrite existing file

大城市里の小女人 提交于 2019-12-22 09:59:52
问题 I'm trying to pass all images in a directory to watermark.php using mod_rewrite in .htaccess. RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule \.jpg$ /watermark.php?path=%{REQUEST_FILENAME} [L] It works fine on local machine, but on my online production server (shared hosting) all image files are served without rewriting. mod_rewrite is enabled online, but it ignores the rule if file exists. What could be wrong? UPDATE Here's my full setup: there's a domain with a subdomain in

Using mod_rewrite to redirect home page ONLY

泄露秘密 提交于 2019-12-22 09:25:59
问题 I have a website that needs redirected, but I can't just redirect the / directory because there are other websites in folders on the server, and doing that redirects them as well. NOT GOOD! So I have my .htaccess file with a bunch of 301 redirects for individual HTML pages, and those work fine. But I need to redirect the home page. Here is what I have to do that: RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^recherchegoldens.com [NC] RewriteRule ^(.*)$ http://whitegoldenretriever

Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests

人盡茶涼 提交于 2019-12-22 09:13:12
问题 So I just inherited a site. The first thing I want to do is build a nice little standard, easy-peezy, CMS that allows for creating a page with any URL (for example: whatever.html). Therefore, if user hits example.com/whatever.html, it should get any db info for whatever.html and display it. This is run of the mill stuff. My problem is that there are quite a few pages on the site (all listed in the .htaccess) that need to continue to be accessible. For instance, /Promotions is linked to

Htaccess redirect Laravel 4

拜拜、爱过 提交于 2019-12-22 09:04:29
问题 I have a Laravel 4 installation, and I used the boilerplate's htaccess to redirect my site from: site.com.br to www.site.com.br (notice the www ). But when I use a route such as site.com.br/TITLE-OF-MY-POST I am redirected to: www.site.com.br/index.php instead of www.site.com.br/TITLE-OF-MY-POST" Does anyone know why? Here my htaccess rules: Laravel's rule <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f

Spring boot cannot find urlrewrite.xml inside jar file

泄露秘密 提交于 2019-12-22 08:57:54
问题 I'm using Spring Boot with an Embedded Tomcat, and the class UrlRewriteFilter can't find the configuration file urlrewrite.xml, this class uses servletcontext.getResourceAsStream(this.confPath) and I read in other article that this method doesn't work when the package is a jar. Someone had this problem ? 回答1: Found in blog post import org.springframework.core.io.Resource; import org.tuckey.web.filters.urlrewrite.Conf; import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter; //Adding