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.
Related
I'm pretty sure this is the first time I have had this issue so I wasn't sure where to look.
The company I work for has a client site which was built in Expression Engine, they now have a new site built with Wordpress. On the old site, they wanted to link to the new Wordpress site through a "Charities" link.
As EE was terrible at dealing with external links, I decided to add a redirect within the .htaccess. The only trouble is, when the link is clicked, the Wordpress site has a "/?charities/" appended to the end URL.
Here is the .htaccess code...
AddType text/x-component .htc
RewriteEngine On
RewriteBase /
Redirect 301 /charities http://www.retail4charities.co.uk
#Handle comment redirection
RewriteCond %{THE_REQUEST} !^POST
RewriteRule ^template_group/?(.*)$ /$1 [R=301,L]
#Handle removal of index.php and template group from EE URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(images|logocms|themes|index\.php|admin\.php) [NC]
RewriteCond %{QUERY_STRING} !^ACT=
RewriteRule ^(.*)$ index.php?$1 [L]
For a working example, head over to http://kudos-software.co.uk and click the charities link to see what is going on.
Any help on this would be greatly appreciated.
Better to use mod_rewrite for this. Switch that line out with this one:
RewriteRule ^charities$ http://www.retail4charities.co.uk [R=302,L]
Change 302 to 301 to make the redirect permanent (cached).
I have to migrate a medium-sized site based on PHP Nuke (less than 2000 posts) to a new WordPress installation. I have problems writing the redirection rules. I tried:
RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^nuke/modules.php$ http://domain.com/%1? [R=301,L]
So
http://domain.com/nuke/modules.php?name=News&file=article&sid=1
should become
http://domain.com/1
It doesn’t work. I tried the .htaccess file in the “nuke”, “modules” and “News” folder with not luck. Any help would be very appreciated.
Here's the working code
RewriteEngine On
RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^modules.php$ http://domain.com/%1? [R=301,L]
If you place the htaccess file in the "nuke" folder, you need to omit the nuke from the pattern:
RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^modules.php$ http://domain.com/%1? [R=301,L]
And make sure you've turned on the rewrite engine:
RewriteEngine On
OK. Hopefully someone can help me with a suggestion-
I have a WordPress multisite using subfolders
I am using WooCommerce
I have a std Ubuntu 12.04/LAMP server with a GoDaddy Certificate installed
If it turn on SSL, it affects my entire domain (obviously) so my primary site ends up as:
'https://main-sitename.com'
My multisite blogs also come up as:
https://main-sitename.com/blogname-1
https://main-sitename.com/blogname-2
and so on. ALL of my menu links are also https which disables outside links because the urls all get prepended with https. :-/
What I am trying to do is get this:
http://main-sitename.com
http://main-sitename.com/blogname-1
http://main-sitename.com/blogname-2
https://main-sitename.com/shop/ (WooCommerce will force HTTPS on checkout and then un-enforce it when done).
So, Anyone have any ideas on how I can remedy this? On an interesting note, when I had the EXACT same site on Rackspace Cloud Sites everything worked fine. When I moved to a self managed Cloudserver this happened. Is there something I missed?
It sounds like SSLRequireSSL has been set for the entire server. Since you only want to enforce HTTPS on /shop/ directory. Add a .htaccess file in that directory that contains:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This will force anyone connecting to your shop with http:// to be redirected to the same URI, but on https://
EDIT 2
This works for me (with www.myserver.com changed to my real server name). I'm using date and name permalinks in WP. As soon as I go to http://www.myserver.com/shop/ I'm redirected to https. It preserves the URI.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Addition to force redirect to https when they visit the shop!
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (shop/.*$) https://www.myserver.com/$1 [R=301,L]
# Back to WordPress changes
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have a site running at my server and here is the content of the .htaccees file
RewriteEngine on
RewriteCond $1 !^(index\.php|img|public|robots\.txt) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
few days back i installed Wordpress in a folder: example.com/my-blog/ as a stand-alone application
but i could not access it. if i remove the .htaccess file it does work fine but that makes a down the site which in any case i cant not afford. please help.
please help, i am newbie in this.
You could exlude your subfolder from rewriting by adding these two lines to your htaccesfile, before your rewriterule:
RewriteCond %{REQUEST_URI} !^/my-blog/ [NC]
RewriteCond %{REQUEST_URI}!=/my-blog [NC]
Ansari is right btw about $1 not being set and therefore, never rewriting anything.
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