Tag Info

Hot answers tagged

9

For your first two rewrites (non-www → www, http → https), the following rule should work: RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !=www.example.com [NC] RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent] Just replace www.example.com with the actual canonical hostname of your site. As for your third ...


3

You need to know the relationship between the project-folder and the sub-folder, ie. which sub-folder a particular project is in. If there is no pattern between project-folder and sub-folder and being restricted to .htaccess then I think you'll need to specify each rewrite manually. You can internally rewrite all requests for the respective project to ...


3

You can just add another RewriteCond directive: RewriteCond %{REQUEST_URI} !^/activity RewriteCond %{REQUEST_URI} !^/members RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] Multiple RewriteCond directives are AND'd together by default. The OR flag can be used if required. I've removed the NC flag - unless you specifically need a case-insensitive match. As ...


3

You can do this by adding another condition. RewriteCond %{REQUEST_URI} !^/members [NC] RewriteCond %{REQUEST_URI} !^/activity [NC] RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] Or, sometimes simpeler, use the OR of a regex: RewriteCond %{REQUEST_URI} !^/(members|activity) [NC] RewriteRule ^(.*)/([0-9]+)/$ /$1/S$2/ [R=301,L] I've removed the .*$ ...


2

You need to add "RewriteOptions Inherit" to each virtual server. See http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriteoptions for details.


2

It looks to me like you would are trying to fetch data from a web service that is running on another port and display it using your main web server. mod_rewrite can be configured to do so. You have to have mod_proxy enabled and use [P] with your rewrite rules. Your directives might look like this: RewriteEngine on RewriteCond %{HTTP_HOST} ...


2

Your are planning on implementing a type of "reverse proxy" in PHP. There is an Apache module that does this already: mod_proxy You might find it easier to configure mod_proxy as a reverse proxy on your client's server rather than use PHP. mod_proxy can even be activated through rewrite rules for specific pages or directories: RewriteEngine On ...


2

Your root .htaccess should look like this: # Mod RewriteRules, some 12 in all RewriteRule ^mod/(.*)$ /moderator/$1 [NC,L] RewriteRule ^signup/(.*)$ /acc/signup/$1 [NC,L] RewriteRule ^signin/(.*)$ /acc/signin/$1 [NC,L] RewriteRule ^signout/(.*)$ /acc/signout/$1 [NC,L] # These are the only two that a front end user will use # category/subCategory ...


2

You can use these three rewrite rules which handle up to 3 levels of directories: RewriteEngine on RewriteRule ^main\/([^\/]+)\/([^\/]+)\/([^\/]+)\/? /parser.php?var1=$1&var2=$2&var3=$3 [L] RewriteRule ^main\/([^\/]+)\/([^\/]+)\/? /parser.php?var1=$1&var2=$2 [L] RewriteRule ^main\/([^\/]+)\/? /parser.php?var1=$1 [L] In those regular ...


2

I suspect you are over thinking this. I am really confused over all your code. One of the things I am finding these days is that people are using example code that is already unnecessarily complicated. As well, people seem to select {???} that offers too much instead of the narrowest selection. Often these things only require 2 lines or 3 at the most and ...


2

The type of redirect you are using is not the problem. 301 redirects are cacheable. In fact they are extremely hard to cache bust. 301 means "permanent" and browsers are very likely to cache 301 redirects with no way with the server to undo one that is already cached. 302 redirects are generally not cached by default unless other headers indicate that ...


2

The problem is that, when you use mod_rewrite in an .htaccess file or a <Directory> section, every successful RewriteRule — even an internal one — causes the request to be restarted internally, and thus the whole rewrite ruleset to be reprocessed. Thus, what's happening is that, when the user visits /page, your internal RewriteRule matches ...


2

I asked this same question on StackOverflow. To get it to work properly, you have to use environment variables: RewriteRule ^page$ /page.html [L,E=LOOP:1] RewriteCond %{ENV:REDIRECT_LOOP} !1 RewriteRule ^page.html$ /page [R=301,L] This is because mod_rewrite does multiple passes through your rules. During the first pass, it sets the environment ...


2

For Q1, the - doesn't mean that processing or iteration would be stopped, simply that the URL path would be passed through without any filtering or processing. The file will continue to execute rules until it reaches the end of the file or a rule is met that has the [L] last rule flag appended to it. To clarify then, RewriteRule .* - ...


2

Triying the same and on my search I found that symfony2 frameworks .htaccess file is doing that at least it is stated in the file that it would. I tried to use it in my own setup but didnt work. Maybe that will help you guys somehow. # Determine the RewriteBase automatically and set it as environment variable. # If you are using Apache aliases to do mass ...


2

From What are the most commonly used and basic Apache htaccess redirects? contributed by bybe: Catch all and redirect non-www to www You should opt to use mod_write for redirecting all requests for non www versions of your site because the $1 varible will catch page names, so example.com/page1/ will automaticly redirect to www.example.com/page1/. ...


2

Use the built-in content negotiation functionality with a type map. You may need to tweak your filenames / URLs or use rewrite rules after applying the type map.


2

RewriteCond %{REQUEST_URI} !^/help/ RewriteRule (.*) /4-3/help [L,NE,R] You are getting a redirect loop here because you are saying that if the URL is not /help/ then redirect to /4-3/help (etc, etc, ...). You need to reverse the logic and only redirect when it is /help/. Change to... RewriteRule ^/?help$ /4-3/help [R,L] NB: This is a temporary (302) ...


2

It looks like that code was developed to stop bots probing humans.txt via query strings. Not Blocked: http://example.com/humans.txt Blocked: http://example.com/?some_path=http://www.google.com/humans.txt? There is plenty of online guides about blocking humans.txt additionally lots of websites explaining what does what, a lot of those rules in that block ...


1

Problem was a WordPress one. It was stripping out the @ when re-writing the non www address to the www address. Problem resolved by adding my old redirect code (which I thought I could dispense with) to top of the .htaccess file: RewriteCond %{HTTP_HOST} ^example\.com$ RewriteRule (.*) http://www.example.com/$1 [R=301,L]


1

You might be able to resolve this by using the NE (noescape) flag on the RewriteRule directive? However, this is admittedly a little puzzling, as even special characters shouldn't be removed entirely, just converted to their hexcode equivalent. The NE flag allows special characters to be passed through untouched. However, your current rules can be greatly ...


1

What is the purpose of the redirect? The 301 Canonical The purpose of your redirect is to assure a canonical domain name. As such, the appropriate HTTP response is a 301. By default, many browsers will cache this indefinitely unless you specify a Cache-Control header. The 302 Confusion In the Google reference you provide, they are talking about landing ...


1

As w3d suggested in the comments, you have an open parenthesis, but not one to close it RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\?sek-muenchenstein\.ch$ [NC] # right here -------------^ RewriteRule ^(.*)$ http://muenchenstein.sek-am.ch/ [R=301,L] Also, in the COND line, you have www\?. I think this might be wrong too, it's now literally looking for ...


1

Not sure if this would encompass your goal completely, but this would turn http www mode into https non-www mode: RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] Then to redirect the whmcs to a new url, you can probably use a simple 301: Redirect 301 ...


1

You can do this with a single RewriteRule. The trick here is to only check for valid username characters, not everything (ie. .* - I wouldn't have thought your usernames could literally be anything?). This would also be more efficient since not every request will match and be processed. For example, assuming your usernames can only consist of ...


1

Problem fixed through one heck of a lot of perseverance. I really should take the time to learn all of mod_rewrite at some point in time… In short I solved the redirect loop with the following condition: RewriteCond %{REQUEST_URI} !^/remote.php/ The above condition basically matches everything that isn't remote.php/ANYTHING_HERE I then used the above ...


1

ok I figured it out RewriteRule ^xy(.*)$ /xy/$1 [R=301,L]


1

Try this: RewriteCond %{REQUEST_URI} !^/xy/ [NC] RewriteCond %{REQUEST_URI} ^/xy(.*)$ [NC] RewriteRule .* http://www.example.org/xy/%1.html [R=301,L] I think should do it. Please let me know and I can update the answer.


1

You may need to use SSLProxyEngine On to make the proxy work via SSL. RewriteEngine On SSLProxyEngine On RewriteCond %{HTTP_HOST} ^babysnakes.com$ [NC] RewriteRule ^/$ https://dancingfool.com/moms.php [P,L] I did a quick test of proxy requests to an SSL page using the [P] flag and it worked for me. (different domains though)



Only top voted, non community-wiki answers of a minimum length are eligible