Jump to content
YYHMedia

301 Redirect Issue with Processwire (Possibly?)

Recommended Posts

So I'm just about finished up migrating a large drupal site to processwire.

I'm now testing some redirects and ran into an interesting problem that --might-- have something to do with processwires default .htaccess file.

So I have a main site

example.com

And a subdomain

products.example.com (apache hosted out of /public_html/products/....)

(and a few other subdomains all in wordpress incidentally).

I need a redirect like:

http://example.com/products/productname.html -> http://products.example.com/productname.html

So I tried something like the following at the top level domain .htaccess:

#othersub
RedirectMatch 301 ^/other/(.*) https://other.example.com/$1 (this works and is a WP site)
 
 
# Complicated Subdomain Redirects
RedirectMatch 301 ^/products/(.*) http://products.example.com/$1 
(this is the PW site and it instead gives me http://products.example.com/productname.html?it=products/productname.html) - which is incorrect.
 
This is either an easy processwire issue for someone who knows the .htaccess file well - or it's a server configuration thing from the subdomain and the url "folder" having the same name.  But I've tried just about every possible variation I can think of and cannot get this to work.
 
Any guidance would be appreciated.  Thanks!
 
 
 
 

Share this post


Link to post
Share on other sites

This is solvable by using Jumplinks, but especially if there's a potential of a lot of traffic, redirect at .htaccess level would be more efficient. Jumplinks is flexible and easy to use, but the downside is that the whole system has to be started just to realise that "oh, this request doesn't belong to this site at all". Waste of time and resources, really :)

Never seen this particular issue, but it sounds like you're, perhaps, doing this at the end of your .htaccess file, or something like that? The .htaccess file adds ?it=... and in a case like this that part of it shouldn't run at all. As a first step I'd try moving this as close to the beginning of the .htaccess file as possible.

This is a simple redirect, so it's quite likely that the issue is something simple too :)

  • Like 1

Share this post


Link to post
Share on other sites

Jumplinks wouldn't work because the problem was one level up (i.e. before processwire).  For what's it worth I "fixed" this by adding a near duplicate redirect after noticing what appeared after it= - namely the name of the subdirectory was removed so

at the top level - yinyanghouse.com

RewriteRule ^theory/herbalmedicine/(.*) https://theory.yinyanghouse.com/theory/herbalmedicine/$1 [R=301,L]
 
 
So in the pw .htaccess I added:
RewriteRule ^herbalmedicine/(.*) https://theory.yinyanghouse.com/theory/herbalmedicine/$1 [R=301,L]
which picks up the part that was being passed "incorrectly" and passes it "correctly".
 
So now
correctly goes to:
(the processwire part of my site)
 
Strange but it works....
 
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By rolisx
      Hi Everyone
      I have a problem here. I have built a site with Processwire on localhost and then transferred to my customer's server. a) it's a windows server (unfortunately) and b) there is a domain-mapping for this site, the domain points to a folder of another domain. Sorry, I can't explain it any better, I don't really understand the different types of servers (why do they have to be different anyway...).
      My problem is, that I see the main website but not the admin page. Do I have to add anything to my .htaccess file?
      I also tried to include web.config file. Not .htaccess nor web.config file have an impact when changing its content. I really have no clue what to do!!
      Links: mcconnellacademy.ch, mcconnellacademy.ch/admin
      Thanks for any pointing in the right direction!
    • By Petra
      Hello everyone,
      I am a newbie in the world of website editing and I have been given a task to figure out how to redirect a long list of some old client's web pages which give 404 error. We have been able to redirect about two thirds of url's by using php database. Unfortunately the rest does not work, using php, due to containing special characters and the command I have tried to generate for couple of web pages, using the tool https://websiteadvantage.com.au/HtAccess-301-Redirect-Generator#heading-ToolResult  is not working using the .htaccess file.
      Would anyone be able to help with the following example?
      1) https://www.berlitzpraha.cz/en/eshop/individual-language-courses?orderby=product_name
      ... to be redirected to https://www.berlitzpraha.cz/en/language-courses-berlitz-shop-online/individual-language-courses-3

      command generated with the tool (not working):
      RewriteEngine On
      RewriteCond %{QUERY_STRING}  ^orderby=product_name$ [NC]
      RewriteRule ^en/eshop/individual-language-courses$ https://www.berlitzpraha.cz/en/language-courses-berlitz-shop-online/individual-language-courses-3? [R=301,NE,NC,L]
      2)
      http://www.berlitzpraha.cz/cs/skupinove-kurzy-jazyku/hledani/zkouset/function.implode ... to be redirected to https://www.berlitzpraha.cz/cs/skupinove-jazykove-kurzy-pro-firmy/
      command generated with the tool (not working):
      RewriteEngine On
      RewriteCond %{HTTP_HOST}  ^www\.berlitzpraha\.cz$ [NC]
      RewriteCond %{QUERY_STRING}  ^$
      RewriteRule ^cs/skupinove-kurzy-jazyku/hledani/zkouset/function\.implode$ https://www.berlitzpraha.cz/cs/skupinove-jazykove-kurzy-pro-firmy/? [R=301,NE,NC,L]
      3)
      https://www.berlitzpraha.cz/en/language-courses-berlitz-shop-online/virtual-language-courses?orderby=product_sku&showall=1 ... to be redirected to https://www.berlitzpraha.cz/en/virtual-language-courses-shop-online/virtual-language-courses-4

      RewriteEngine On
      RewriteCond %{QUERY_STRING}  ^orderby=product_sku&showall=1$ [NC]
      RewriteRule ^en/language-courses-berlitz-shop-online/virtual-language-courses$ https://www.berlitzpraha.cz/en/virtual-language-courses-shop-online/virtual-language-courses-4? [R=301,NE,NC,L]
       
      Thank you very much in advance.
      Petra
    • By VirtuallyCreative
      So being a LAMP server guy, recently at my work I've had to use Microsoft's' Azure Cloud to host some micro-apps of ours and I got to playing around with the platform. It's pretty nifty!
      Naturally, I tried to install ProcessWire to play around with Web Apps + SQL App Service to see what I can get away with on the Free Tier (rather then spinning up a full LAMP VM machine which is the way Bitnami installs ProcessWire, costing $60CAD/mo).
      Turns out installing ProcessWire is pretty smooth sailing except for one part: .htaccess mod_rewrite rules when you're not using Apache, as this is Azure Cloud so it's running PHP7 on IIS Microsoft Server and requires rewrite rules to be in a web.config file instead.

      Doing some digging, I found tools that convert .htaccess over to web.config and was curious if anyone with experience using Microsoft .NET could see if the rules from the .htaccess actually do translate in the same way when written in XML for web.config?
      Default ProcessWire v3.0 .htaccess file (comments, commented out commands removed):
      Options -Indexes Options +FollowSymLinks ErrorDocument 404 /index.php <Files favicon.ico> ErrorDocument 404 "The requested file favicon.ico was not found. </Files> <Files robots.txt> ErrorDocument 404 "The requested file robots.txt was not found. </Files> <IfModule mod_headers.c> Header always append X-Frame-Options SAMEORIGIN Header set X-XSS-Protection "1; mode=block" </IfModule> <FilesMatch "\.(inc|info|info\.json|module|sh|sql)$|^\..*$|composer\.(json|lock)$"> <IfModule mod_authz_core.c> Require all denied </IfModule> <IfModule !mod_authz_core.c> Order allow,deny </IfModule> </FilesMatch> <IfModule mod_php5.c> php_flag magic_quotes_gpc off php_flag magic_quotes_sybase off php_flag register_globals off </IfModule> DirectoryIndex index.php index.html index.htm <IfModule mod_rewrite.c> RewriteEngine On AddDefaultCharset UTF-8 <IfModule mod_env.c> SetEnv HTTP_MOD_REWRITE On </IfModule> RewriteRule "(^|/)\.(?!well-known)" - [F] RewriteCond %{REQUEST_URI} !(^|/)site-[^/]+/install/[^/]+\.(jpg|jpeg|png|gif)$ [OR] RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets/(cache|logs|backups|sessions|config|install|tmp)($|/.*$) [OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/install($|/.*$) [OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets.*/-.+/.* [OR] RewriteCond %{REQUEST_URI} (^|/)(wire|site|site-[^/]+)/(config|index\.config|config-dev)\.php$ [OR] RewriteCond %{REQUEST_URI} (^|/)(wire|site|site-[^/]+)/templates-admin($|/|/.*\.(php|html?|tpl|inc))$ [OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))$ [OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets($|/|/.*\.php)$ [OR] RewriteCond %{REQUEST_URI} (^|/)wire/(core|modules)/.*\.(php|inc|tpl|module|info\.json)$ [OR] RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/modules/.*\.(php|inc|tpl|module|info\.json)$ [OR] RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|htaccess)\.(txt|md|textile)$ [OR] RewriteCond %{REQUEST_URI} (^|/)site-default/ RewriteRule ^.*$ - [F,L] RewriteCond %{REQUEST_URI} "^/~?[-_.a-zA-Z0-9/]*$" [OR] RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d [OR] RewriteCond %{REQUEST_FILENAME} !(favicon\.ico|robots\.txt) [OR] RewriteRule ^(.*)$ index.php?it=$1 [L,QSA] </IfModule>  
      Converted web.config file:
      <rewrite> <rules> <rule name="www_mysite_com:non-80"> <match url="&quot;(^|/)\.(?!well-known)&quot;" ignoreCase="false" /> <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> </rule> <rule name="www_mysite_com:80" stopProcessing="true"> <match url="^.*$" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="(^|/)site-[^/]+/install/[^/]+\.(jpg|jpeg|png|gif)$" ignoreCase="false" negate="true" /> <add input="{URL}" pattern="(^|/)\.htaccess$" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/assets/(cache|logs|backups|sessions|config|install|tmp)($|/.*$)" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/install($|/.*$)" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/assets.*/-.+/.*" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(wire|site|site-[^/]+)/(config|index\.config|config-dev)\.php$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(wire|site|site-[^/]+)/templates-admin($|/|/.*\.(php|html?|tpl|inc))$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/assets($|/|/.*\.php)$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)wire/(core|modules)/.*\.(php|inc|tpl|module|info\.json)$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(site|site-[^/]+)/modules/.*\.(php|inc|tpl|module|info\.json)$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)(COPYRIGHT|INSTALL|README|htaccess)\.(txt|md|textile)$" ignoreCase="false" /> <add input="{URL}" pattern="(^|/)site-default/" ignoreCase="false" /> </conditions> <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" /> </rule> <rule name="www_mysite_com:80" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{URL}" pattern="&quot;^/~?[-_.a-zA-Z0-9/]*$&quot;" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" pattern="(favicon\.ico|robots\.txt)" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php?it={R:1}" appendQueryString="true" /> </rule> </rules> </rewrite>
    • By Tony Carnell
      Hi all,
       
      I'm just looking for some advice really.
      We've got a current website in the root of our hosting account and have been developing a new Processwire powered one in a sub-directory.
      We're now getting close to setting the new site live and I'm wondering which is best; leave the new site in the sub-directory and modify the .htaccess file to point to it, or remove the existing site and move the new one across to the root.
      We're also looking to install Piwik in its own folder too, together with the Piwik Analytics module. Would this work if the site remains in the sub-directory, because Piwik would effectively be in a sub-directory off a sub-directory?
      Basically it comes down to which is the more satisfactory option, leave it where it is versus move it to the root.
      If it stays in the sub-directory, I'll want to change the .htaccess file to point at that location, but also hide the sub-directory so it looks as if it's running from the root, e.g. the site is running from www.example.com/cms/ but the visitor never sees the /cms/ in the urls.
      Thanks in advance for any advice.
      Tony.
    • By Osorio
      Hi   

      I am currently experimenting with Google Polymer / Web Components, which relies on html-imports.
      I noticed that Processwire's .htaccess blocks access to .html files in the template folder.
      # Block access to any PHP or markup files in /site/templates/ RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))$ [OR] Is it safe to reallow access to .html-files in "/templates"? Or maybe just to a specific subfolder, like "templates/html-imports/*.html"? 
×
×
  • Create New...