Strange rewriterule difficulty - what am i doing wrong - drupal

I am trying to rewrite everything by appending a language code at the beginning of the path. When I use this: RewriteRule ^(.*)3$ es/$1browsing mysite.com/admin3 properly loads mysite.com/es/admin.
But i do not know why, but when I use this: RewriteRule ^(.*)$ es/$1
browsing mysite.com/admin does load mysite.com/es/admin BUT it loads so slow, and in plain html (no css, no images, etc).
Can somebody point out what am I doing wrong? It's driving me nuts - i', a regexp noob.
Thanks.
UPDATE:
We already have a multilingual site running. But we wanted to provide alternative access to the other languages via local domains. So we wanted to have mysite.com/es while having newdomain.es at the same time. This is not possible via Drupal's "domain name" language negotiation.
Now I've already setup newdomain.es/es but I want users to only see newdomain.es on the address bar.

I just realised that one could use the subdomain option from Drupal internationlisation under /admin/config/regional/language/configure.
If you choose [configure] next to URL, you can enable domain prefix like es.mysite.com.
And then you can point your DNS of mysite.es to es.mysite.com. Just add to DNS of mysite.es the value www - CNAME - es.mysite.com (Note that sometimes you might need an extra dot in the destination like www - CNAME - es.mysite.com.).

The problem I was having was that, files are also forwarded (e.g, css, javascript, images, etc). This is how I solved it:
RewriteCond %{HTTP_HOST} ^mysite.es$ [NC]
# optional: add other language exceptions so they still work
# RewriteCond %{REQUEST_URI} !^/fr/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ es/$1 [NC,QSA]
# for homepage
RewriteCond %{HTTP_HOST} ^mysite.es$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ es

Related

How to make a htaccess redirection when a WP is living there?

Let's imagine I have somedomain.com and in the root, I have a standard \index.php that opens an online service I've developed.
Also, I have a folder called \wpress that opens a Wordpress Site, so when I go to
somedomain.com/index.php opens my online tool, no problem
somedomain.com/wpress opens my Wordpress, no problem
What I need to do is, to avoid giving a weird address with an .PHP implied, I would like to have something like this:
somedomain.com/tool or somedomain.com/tool/ and then a redirection is done to somedomain.com/index.php
I've tried but sometimes WP takes control... Weird...
-------------------------------
RewriteBase /
RewriteEngine on
Redirect 301 /tool$ /index.php
#This zone is to redirect to WP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /wpress [L,QSA]
--------------------------------
Not sure what I'm doing wrong, any help will be GREAT you htaccess gurus!

Wordpress friendly URL for image directory

There's often a need to use images in the Wordpress theme folder for other uses (for instance in an email).
These URLs take the form;
http://example.com/wordpress/wp-content/themes/mytheme/images/image.jpg or
http://example.com/wordpress/wp-content/uploads/path-to-my-image/image.jpg
What sort of redirect in htaccess would I need to use a simple url
http://example.com/images/image.jpg?
I am, of course, assuming http://example.com/images isn't used for anything else.
I'd say something like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} images/(.*)$
RewriteRule ^.*$ http://example.com/wordpress/wp-content/themes/mytheme/images/%1 [L,R=303]

Specific Wordpress page SSL exception through htaccess

I know this is not the first time someone has asked this, but I tried other solutions and they don't seem to work.
So I have a website with a SSL certificate and a redirect rule in my .htaccess file to point visitors to https. However, there is one specific page I want to exclude from SSL.
This is the code in my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So my question is, how do I create a rule that excludes www.example.com/shop from SSL?
Most likely you can use another RewriteCond on the redirect to block redirecting for that particular URL. However, how are you going to handle the resources loaded by that page? It will load stuff like images, CSS, Javascript, etc. Should those be loaded over plain old HTTP too? And what happens when something clicks on a like to view their shopping cart, will it go to another URL (and thus go over HTTPS again)?
I'm not entirely sure what you want to achieve, but it sounds a bit silly to me. Why would you want to exclude only one particular page from a safe & secure connection? (And why wouldn't you serve the whole site over TLS?) But maybe you tell us the reason for this so maybe we can help you find a different solution?

mod_rewrite issues using ISAPI_rewriter on IIS6

I'm hoping non-IIS people can help me on this though the issue I'm having is based around an IIS6 server running ISAPI_Rewriter.
The situation is that I'm running Wordpress on IIS6, ISAPI_Rewriter is being used to act as a replacement for mod_rewrite and is functioning properly. My problem is that when I get it to rewrite my URLs for Wordpress (so I don't need the index.php filename in it) it shows a 404. After much searching I found the problem was because part of the ASP.net (or something similar) was adding eurl.axd/[random string] to the end of the URLs and so this was being fed into the Wordpress request and breaking it. I set the Wordpress template to output the requested URL and it looks something like this:
http://www.example.com/index.php/about/eurl.axd/b552863f2d5e9841b5d8b79b44ac02e8/
I believe this is because of the pecking order of various things in the IIS system and the culprit is required to run another part of the project. I'd prefer to keep using ISAPI_Rewriter to pretty up the URLs so I'd like to know this:
Is there any way of getting mod_rewrite to remove eurl.axd/[string] before feeding it on to the system?
My .htaccess file currently appears as such:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# The following line excludes folders from rewriting
RewriteCond %{REQUEST_URI} !^/folder-name/
RewriteRule ^/(.*)$ /$1 [NC,L]
Thanks for all the help, it is always greatly appreciated.
EDIT: Have adjusted my htaccess based on suggestions and it seems to work well from the brief tests I have carried out. Have posted it below.
RewriteEngine on
RewriteBase /
# This is used to strip ASP.net eurl.axd bits
# from the URL so wordpress can use permalinks
# For the root
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^eurl\.axd/[0-9a-f]+/$ index.php [NC,L]
# For internal permalinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wp-admin/
RewriteRule ^(.*)/eurl\.axd/[0-9a-f]+/$ index.php/$1 [NC,L]
Something like this near the top of your list of rewrites should work:
RewriteRule ^(.*)/eurl\.axd/[0-9a-f]+/$ /$1
I use the following regex as first rule with Ionics Isapi Rewriter for web sites running on ASP.NET 4 on IIS 6 to remedy the problems caused by the breaking change introduced with ASP.NET 4 :
RewriteRule ^(.*)/eurl.axd/[a-f0-9]{32}(.*)$ $1$2
This let me again use extensionless urls.
Note that the second group captures the querystring if present and restitutes it to the rewritten url.
And yes, it's a feature, not a bug.
I ran into a similar issue with v4.0 ASP.Net extension less URL feature on II6 and found a solution through ISAPI Rewrite Module provider, the does not require turning it off. Theissue and the solution as we experienced it is documented here http://www.vanadiumtech.com/OurBlog/post/2011/08/12/Cause-of-eurlaxd.aspx

URL Rewrite on IIS7 for Wordpress

I am using shared hosting with IIS7 and support for PHP. I am trying to run a wordpress blog with "pretty urls" (removing index.php). The hosting provider doesn't want to install the URLRewrite module, so that option isn't available to me. I found a plugin for wordpress that will remove the index.php from permalink URLs and changing the 404 page to index.php is supposed to do the trick... that isn't working either.
I'm familiar with URL rewriting for an ASP.NET website, but I'm not sure how I would go about it for PHP. The hosting setup seems to support ASP.NET and PHP at the same time, so I'm thinking it would be possible to run the rewrite code through ASP.NET, but I'm not sure how to go about it.
Does anybody have any experience with this or any ideas about the best approach to take. If anything leads me in the right direction or if I figure it out myself, I will be more than happy to share the code here for anybody else that may need it.
I'm using the ManagedFusion Url Rewriter and a custom 404 error page on my blog.
The ManagedFusion Url Rewriter requires a file called ManagedFusion.Rewriter.rules that mimics .htaccess, I had to play around with it quite a bit to get it right so I'll include what I currently have in mine:
# Managed Fusion Url Rewriter
# http://managedfusion.com/products/url-rewriter/
#
# Developed by: Nick Berardi
# Support: support#managedfusion.com
#
RewriteEngine on
#
# Place Rules Below
#
# misc WordPress rewrites
RewriteRule ^/wp-login\.php$ /wp-login.php [L]
RewriteRule ^/wp-comments-post\.php$ /wp-comments-post.php [L]
RewriteRule ^/wp-admin/(.*)$ /wp-admin/$1 [L]
# deny access to evil robots site rippers offline browsers and other nasty scum
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]
# remove www
RewriteCond %{HTTP_HOST} ^www\.robboek\.com$ [NC]
RewriteRule ^(.*)$ http://robboek.com$1 [R=301]
# redirect old urls
RewriteRule ^/2008/12/blog-on-hold.html$ /2008/12/12/blog-on-hold/ [R=301]
RewriteRule ^/2008/11/google-chrome-wont-start-in-vista-x64\.html$ /2008/11/16/google-chrome-wont-start-in-vista-x64/ [R=301]
RewriteRule ^/2008/11/pass-community-summit-2008-events.html$ /2008/11/14/pass-community-summit-2008-events-calendar/ [R=301]
RewriteRule ^/2008/11/fort-stevens-camping-trip.html$ /2008/11/14/fort-stevens-camping-trip/ [R=301]
RewriteRule ^/2008/10/first-post.html$ /2008/10/10/first-post/ [R=301]
RewriteRule ^/blog/CommentView,guid,1d8cba50-0814-4c89-86df-eca669973e8e.aspx$ /2006/09/29/junctions-in-windows-vista/ [R=301]
RewriteRule ^/blog/2006/09/29/JunctionsInWindowsVista.aspx$ /2006/09/29/junctions-in-windows-vista/ [R=301]
# rewrite all nonexistent files and directories to use index.php for WordPress
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php$1
The rules handle the pretty urls, remove the www, and redirect several old urls from a previous blog.
I also have a file "404.php" that I have setup as my custom 404 error page. This is not needed for the pretty urls, but will allow you to use the wordpress 404 page in custom themes. Here are the contents:
<?php
$qs = $_SERVER['QUERY_STRING'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
I hope that helps. It has been working very well for me so far.
-Rob
Update: I just posted a blog article on my experience using WordPress on IIS7
Thank you all for the suggestions.
My host ended up installing IIRF and it worked like a charm. There is a file called IsapiRewrite4.ini for the rewrite rules. In order to get my Wordpress install running without the index.php in the URL, all I had to do was add:
RewriteRule ^/sitemap.xml$ - [L]
RewriteRule ^/(?!index.php)(?!wp-)(.*)$ /index.php/$1
The first line allows requests for a sitemap.xml file. The second line handles removing index.php from the URL. It seems to be fine from a performance standpoint as well, I haven't seen any issues with pages responding slowly at all.
Hopefully this will help somebody else who needs similar functionality.
Changing the 404 page to index.php is supposed to do the trick. If it does not, the plugin may not support IIS.
There is a xml "web.config" file in IIS that does what .htaccess does in Apache HTTPD. (i.e. Override web server setting by static configuration file). It is widely used in ASP.NET application.
Please read Enable custom errors in WordPress on IIS 7.0
If this does not work either, you may try to ask your service provider to set it for you.
They can configure this setting via IIS Management Console GUI.

Resources