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
Related
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
I am in the process of moving my current static site to Wordpress, using the same domain name.
Both old and new sites have their content in the root folder and also have identical file names, but on the new (Wordpress) site, I have removed the .php extension that exists on the current site and added a trailing slash, as per Wordpress permalinks.
So I need to redirect all the old pages (for example):
/contact-us.php -> /contact-us/
I have tried the well-documented options such as (and variations on this):
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /$1 [R=301,L]
But this seems to be conflicting with the Wordpress .htaccess rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
When I try to access www.site.com/contact-us.php, I am getting either an infinite loop OR a redirect to www.site.com/index (no .php, no trailing slash), which Wordpress displays as a 404 page.
I have tried with and without the first set of Rewrite conditions (as I see they are duplicated in the Wordpress rules), and also placed my rule before and after the Wordpress rules. No joy. I've also been Googling for the last few hours but no one seems to have addressed this specific problem. I do usually find what I am looking for by searching, so it's in desperation that I'm actually posting (and which is why it's my first post!)
If anyone can help out, I would be very grateful.
It appears you will run into loops when trying an .htaccess redirect because of the php suffix. Maybe someone else knows a solution.
But try a plugin called Redirection « WordPress Plugins. Out of curiosity, I tried a redirect from contact-us.php to contact-us/ and it worked fine. The plugin redirects via php rather than writing to .htaccess, and that may be the difference.
I use the plugin all the time to mostly log 404's and do a few redirects. It doesn't take too much site overhead.
Be sure and set Options to not do "URL Monitoring," as that will set up automatic redirects to to posts/pages that have their permalinks manually changed. And set your 404 logging to a day or two, because the logs can quickly get big and result in huge database tables.
Try using this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Rewrite /something.php to /something/
RewriteRule (.*)/(.*)\.php$ $1/$2/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This method would rewrite:
/contact-us/test/hello.php -> /contact-us/test/hello/
If you don't want subdirectory rewriting replace line 6 with:
RewriteRule /(.*)\.php$ /$1/ [R=301,L]
what have you done since Wordpress v3.0, all direct PHP files are not working in WP, all are returning 404 page not found, I have created one plugin, it's loading /wp-content/plugins/myplugin/direct.php file and what am I seeing now, it shows me my WP site with title PAGE NOT FOUND 404, help me please I can't work with WP any more, all direct PHP files are not accessible and tracked as 404.
What should I do to turn off that terrible 404 or get my php files loaded.
Check your .htaccess file, maybe all URLs now are mapped to the index.php file of Wordpress.
Based on the provided rewrite rules, I would suggest to use this instead:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*shop/images/(\d+)/?\??(.*)$ /wp-content/plugins/shopp/core/image.php?siid=$1&$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm not understanding the question. You're saying that you've created a plugin, and it's not calling in the files properly? (I'm assuming by "direct PHP file access" you mean you can't load a particular file that's within your plugin directory?)
Sounds like you're not using the correct paths. You should be using things like WP_PLUGIN_URL constants that are set up for you via WordPress (http://codex.wordpress.org/Determining_Plugin_and_Content_Directories) - i.e it doesn't sound like an .htaccess issue, it sounds like improper coding in the plugin.
Of course, without knowing what code you are using, it's difficult to say what the issue could be.
Are all requests handled in index.php?
Yes. All* requests will go through index.php there is a rewrite rule in the .htaccess file which masks this and gives user friendly urls.
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
If Drupal can't invoke these rules then you will see index.php in the browser URL.
**There are cron.php and update.php which don't but these are special files for admin so are not part of the run of the mill site.*
Yes. If you're looking for certain code snippets that handles URL parsing and calls various modules then take a look inside bootstrap.inc
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.